File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
solution/2200-2299/2225.Find Players With Zero or One Losses Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,34 @@ func findWinners(matches [][]int) [][]int {
167
167
}
168
168
```
169
169
170
+ ### ** JavaScript**
171
+
172
+ ``` js
173
+ var findWinners = function (matches ) {
174
+ const onlyWins = new Set (),
175
+ oneLose = new Set (),
176
+ moreLosses = new Set ();
177
+
178
+ for (const [winner , loser ] of matches) {
179
+ if (! moreLosses .has (loser)) {
180
+ if (oneLose .has (loser)) {
181
+ oneLose .delete (loser);
182
+ moreLosses .add (loser);
183
+ } else {
184
+ onlyWins .delete (loser);
185
+ oneLose .add (loser);
186
+ }
187
+ }
188
+
189
+ if (! moreLosses .has (winner) && ! oneLose .has (winner)) {
190
+ onlyWins .add (winner);
191
+ }
192
+ }
193
+
194
+ return [[... onlyWins].sort ((a , b ) => a - b), [... oneLose].sort ((a , b ) => a - b)];
195
+ };
196
+ ```
197
+
170
198
### ** TypeScript**
171
199
172
200
``` ts
You can’t perform that action at this time.
0 commit comments