给定一个字符串集合,返回字符串中不包含重复字符的字符串集合
1 /** 2 * @param arr 给定一个字符串集合 3 * @return 返回字符串中不包含重复字符的字符串集合 4 */ 5 public List<String> findStr(List<String> arr) { 6 List<String> ans = new ArrayList<>(); 7 for (String s : arr) { 8 int mask = 0; 9 for (int i = 0; i < s.length(); ++i) { 10 int ch = s.charAt(i) - 'a'; 11 if (((mask >> ch) & 1) != 0) { 12 mask = 0; 13 break; 14 } 15 mask |= 1 << ch; 16 } 17 if (mask > 0) { 18 ans.add(s); 19 } 20 } 21 return ans; 22 }
输入:arr = ["unn","iq","ue","cha"] 输出:arr = ["iq","ue","cha"] "unn"中包含重复字符'n'