代码:
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;}
}