Thursday, September 14, 2023

odd string diff

 https://leetcode.com/problems/odd-string-difference/

Beats 19.92%of users with Java
 
class Solution {
public String oddString(String[] words) {
HashMap<String, String> res = new HashMap();
for (String s : words) {
int[] diff2 = new int[words[0].length() - 1];
extracted(s.toCharArray(), diff2);
res.put(Arrays.toString(diff2), res.getOrDefault(Arrays.toString(diff2),"")+ s);
}

return res.values().stream()
.min(Comparator.comparingInt(String::length))
.get();
}

private void extracted(char[] charArray, int[] diff) {
for (int i = 0; i < charArray.length - 1; i++) {
diff[i] = charArray[i + 1] - charArray[i];
}
}
}

 

No comments:

sony xperia 10 VI did not like the case

After iphone 16 I wanted to test an android and looks like sony xperia 10 VI is nice, which is 6.1 inches, but it was narrow and longer than...