本文主要是介绍1593. 拆分字符串使唯一子字符串的数目最大,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1593. 拆分字符串使唯一子字符串的数目最大
Java:
class Solution {int cnt;int max;Set<String> set;private void dfs(String s, int pos, int len) {if (pos == len) {max = Math.max(max, cnt);return;}for(int i = pos; i < len; ++i) {String s1 = s.substring(pos, i + 1);if (!set.contains(s1)) {set.add(s1);++cnt;dfs(s, i + 1, len);--cnt;set.remove(s1);}}}public int maxUniqueSplit(String s) {cnt = 0;max = 0;set = new HashSet<>();dfs(s, 0, s.length());return max;}
}
这篇关于1593. 拆分字符串使唯一子字符串的数目最大的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!