本文主要是介绍Hot100-80(Leetcode763划分字母区间),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码:
class Solution {public List<Integer> partitionLabels(String s) {int n = s.length();boolean f[] = new boolean[n+1];Map<Character,Integer> map = new HashMap<>();for(int i=0;i<n;i++){if(!map.containsKey(s.charAt(i))){f[i]=true;map.put(s.charAt(i),i);}else{int first = map.get(s.charAt(i));for(int idx=first+1;idx<=i;idx++){if(f[idx]==true){f[idx]=false;}}}}int x = 0;List<Integer> res = new ArrayList<>();f[n]=true;for(int i=1;i<=n;i++){if(f[i]==true){res.add(i-x);x = i;}}return res;}
}
这篇关于Hot100-80(Leetcode763划分字母区间)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!