@@ -54,13 +54,83 @@ The odd array out is [1, 1], so we return the corresponding string, "abc&qu
54
54
### ** Python3**
55
55
56
56
``` python
57
-
57
+ class Solution :
58
+ def oddString (self , words : List[str ]) -> str :
59
+ cnt = defaultdict(list )
60
+ for w in words:
61
+ d = [str (ord (b) - ord (a)) for a, b in pairwise(w)]
62
+ cnt[' ,' .join(d)].append(w)
63
+ return next (v[0 ] for v in cnt.values() if len (v) == 1 )
58
64
```
59
65
60
66
### ** Java**
61
67
62
68
``` java
69
+ class Solution {
70
+ public String oddString (String [] words ) {
71
+ Map<String , List<String > > cnt = new HashMap<> ();
72
+ for (var w : words) {
73
+ List<String > d = new ArrayList<> ();
74
+ for (int i = 0 ; i < w. length() - 1 ; ++ i) {
75
+ d. add(String . valueOf(w. charAt(i + 1 ) - w. charAt(i)));
76
+ }
77
+ cnt. computeIfAbsent(String . join(" ," , d), k - > new ArrayList<> ()). add(w);
78
+ }
79
+ for (var v : cnt. values()) {
80
+ if (v. size() == 1 ) {
81
+ return v. get(0 );
82
+ }
83
+ }
84
+ return " " ;
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### ** C++**
90
+
91
+ ``` cpp
92
+ class Solution {
93
+ public:
94
+ string oddString(vector<string >& words) {
95
+ unordered_map<string, vector<string >> cnt;
96
+ for (auto& w : words) {
97
+ string d;
98
+ for (int i = 0; i < w.size() - 1; ++i) {
99
+ d += (char) (w[ i + 1] - w[ i] );
100
+ d += ',';
101
+ }
102
+ cnt[ d] .emplace_back(w);
103
+ }
104
+ for (auto& [ _ , v] : cnt) {
105
+ if (v.size() == 1) {
106
+ return v[ 0] ;
107
+ }
108
+ }
109
+ return "";
110
+ }
111
+ };
112
+ ```
63
113
114
+ ### **Go**
115
+
116
+ ```go
117
+ func oddString(words []string) string {
118
+ cnt := map[string][]string{}
119
+ for _, w := range words {
120
+ d := make([]byte, len(w)-1)
121
+ for i := 0; i < len(w)-1; i++ {
122
+ d[i] = w[i+1] - w[i]
123
+ }
124
+ t := string(d)
125
+ cnt[t] = append(cnt[t], w)
126
+ }
127
+ for _, v := range cnt {
128
+ if len(v) == 1 {
129
+ return v[0]
130
+ }
131
+ }
132
+ return ""
133
+ }
64
134
```
65
135
66
136
### ** TypeScript**
0 commit comments