http://instant.1point3acres.com/thread/134194
Delete SubStrings: 给一个String s和一个String t, 返回一共能在s中删除t多少次。 例如s = aabb, t = ab, return = 2; s = aabcbdc, t = abc, return 1;
http://www.mitbbs.com/article_t/Recommend/31524609.html
Delete SubStrings: 给一个String s和一个String t, 返回一共能在s中删除t多少次。 例如s = aabb, t = ab, return = 2; s = aabcbdc, t = abc, return 1;
static int deleteSubStrings(String a, String b, Map<String, Integer> dp) { if (dp.containsKey(a)) return dp.get(a); int ret = 0; for (int i = 0; i < a.length(); i++) { if (a.startsWith(b, i)) { ret = Math.max(ret, 1 + deleteSubStrings(a.substring(0, i) + a.substring(i + b.length()), b, dp)); } } dp.put(a, ret); return ret; } public static void main(String[] args) { System.out.println(deleteSubStrings("aabb", "ab", new HashMap<String, Integer>())); System.out.println(deleteSubStrings("aabcbdc", "abc", new HashMap<String, Integer>())); }
http://www.mitbbs.com/article_t/Recommend/31524609.html