Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,57 @@ func findWinners(matches [][]int) [][]int {
}
```

### **TypeScript**

```ts
function findWinners(matches: number[][]): number[][] {
const cnt: Map<number, number> = new Map();
for (const [a, b] of matches) {
cnt.set(a, cnt.has(a) ? cnt.get(a) : 0);
cnt.set(b, (cnt.get(b) || 0) + 1);
}
const ans: number[][] = [[], []];
for (let [u, v] of cnt.entries()) {
if (v < 2) {
ans[v].push(u);
}
}
ans[0].sort((a, b) => a - b);
ans[1].sort((a, b) => a - b);
return ans;
}
```

### **JavaScript**

```js
/**
* @param {number[][]} matches
* @return {number[][]}
*/
var findWinners = function (matches) {
const cnt = new Map();
for (const [a, b] of matches) {
cnt.set(a, cnt.has(a) ? cnt.get(a) : 0);
cnt.set(b, (cnt.get(b) || 0) + 1);
}
const ans = [[], []];
for (let [u, v] of cnt.entries()) {
if (v < 2) {
ans[v].push(u);
}
}
ans[0].sort((a, b) => a - b);
ans[1].sort((a, b) => a - b);
return ans;
};
```

```js
/**
* @param {number[][]} matches
* @return {number[][]}
*/
var findWinners = function (matches) {
const onlyWins = new Set(),
oneLose = new Set(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,57 @@ func findWinners(matches [][]int) [][]int {
}
```

### **TypeScript**

```ts
function findWinners(matches: number[][]): number[][] {
const cnt: Map<number, number> = new Map();
for (const [a, b] of matches) {
cnt.set(a, cnt.has(a) ? cnt.get(a) : 0);
cnt.set(b, (cnt.get(b) || 0) + 1);
}
const ans: number[][] = [[], []];
for (let [u, v] of cnt.entries()) {
if (v < 2) {
ans[v].push(u);
}
}
ans[0].sort((a, b) => a - b);
ans[1].sort((a, b) => a - b);
return ans;
}
```

### **JavaScript**

```js
/**
* @param {number[][]} matches
* @return {number[][]}
*/
var findWinners = function (matches) {
const cnt = new Map();
for (const [a, b] of matches) {
cnt.set(a, cnt.has(a) ? cnt.get(a) : 0);
cnt.set(b, (cnt.get(b) || 0) + 1);
}
const ans = [[], []];
for (let [u, v] of cnt.entries()) {
if (v < 2) {
ans[v].push(u);
}
}
ans[0].sort((a, b) => a - b);
ans[1].sort((a, b) => a - b);
return ans;
};
```

```js
/**
* @param {number[][]} matches
* @return {number[][]}
*/
var findWinners = function (matches) {
const onlyWins = new Set(),
oneLose = new Set(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
/**
* @param {number[][]} matches
* @return {number[][]}
*/
var findWinners = function (matches) {
const onlyWins = new Set(),
oneLose = new Set(),
moreLosses = new Set();

for (const [winner, loser] of matches) {
if (!moreLosses.has(loser)) {
if (oneLose.has(loser)) {
oneLose.delete(loser);
moreLosses.add(loser);
} else {
onlyWins.delete(loser);
oneLose.add(loser);
}
}

if (!moreLosses.has(winner) && !oneLose.has(winner)) {
onlyWins.add(winner);
const cnt = new Map();
for (const [a, b] of matches) {
cnt.set(a, cnt.has(a) ? cnt.get(a) : 0);
cnt.set(b, (cnt.get(b) || 0) + 1);
}
const ans = [[], []];
for (let [u, v] of cnt.entries()) {
if (v < 2) {
ans[v].push(u);
}
}

return [[...onlyWins].sort((a, b) => a - b), [...oneLose].sort((a, b) => a - b)];
ans[0].sort((a, b) => a - b);
ans[1].sort((a, b) => a - b);
return ans;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function findWinners(matches: number[][]): number[][] {
const cnt: Map<number, number> = new Map();
for (const [a, b] of matches) {
cnt.set(a, cnt.has(a) ? cnt.get(a) : 0);
cnt.set(b, (cnt.get(b) || 0) + 1);
}
const ans: number[][] = [[], []];
for (let [u, v] of cnt.entries()) {
if (v < 2) {
ans[v].push(u);
}
}
ans[0].sort((a, b) => a - b);
ans[1].sort((a, b) => a - b);
return ans;
}