You are viewing a single comment's thread. Return to all comments →
JAVA
public static List<String> weightedUniformStrings(String s, List<Integer> queries) { Set<Integer> weights = new HashSet<>(); int count = 1; List<String> result = new ArrayList<>(); for (int i = 0; i < s.length(); i++) { weights.add(count * ((int) s.charAt(i) - 96)); if (i + 1 < s.length() && s.charAt(i) == s.charAt(i + 1)) { count++; } else { count = 1; } } for (Integer query : queries) { if (weights.contains(query)) { result.add("Yes"); } else { result.add("No"); } } return result; }
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
JAVA