We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 46bd910 commit 3054444Copy full SHA for 3054444
Easy/Odd String Difference.java
@@ -0,0 +1,23 @@
1
+class Solution {
2
+ public String oddString(String[] words) {
3
+ Map<String, Set<String>> diffCounter = new HashMap<>();
4
+ for (String word : words) {
5
+ String key = getDiffCounter(word);
6
+ diffCounter.computeIfAbsent(key, k -> new HashSet<>()).add(word);
7
+ }
8
+ for (String key : diffCounter.keySet()) {
9
+ if (diffCounter.get(key).size() == 1) {
10
+ return diffCounter.get(key).iterator().next();
11
12
13
+ return "";
14
15
+
16
+ private static String getDiffCounter(String word) {
17
+ StringBuilder sb = new StringBuilder();
18
+ for (int i = 1; i < word.length(); i++) {
19
+ sb.append(word.charAt(i) - word.charAt(i - 1)).append('|');
20
21
+ return sb.toString();
22
23
+}
0 commit comments