Skip to content

Commit 846fd74

Browse files
committed
add 1706 ts solution
1 parent 2b97495 commit 846fd74

File tree

1 file changed

+33
-0
lines changed
  • Problems/24-Where-Will-the-Ball-Fall

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function findBall(grid: number[][]): number[] {
2+
let m = grid.length;
3+
let n = grid[0].length;
4+
let res: number[] = [];
5+
6+
for (let i = 0; i < n; i++) {
7+
let x = 0,
8+
y = i;
9+
while (x < m) {
10+
if (grid[x][y] === 1) {
11+
if (y === n - 1) {
12+
break;
13+
} else if (grid[x][y + 1] === -1) {
14+
break;
15+
}
16+
x++;
17+
y++;
18+
} else {
19+
if (y === 0) {
20+
break;
21+
} else if (grid[x][y - 1] === 1) {
22+
break;
23+
}
24+
x++;
25+
y--;
26+
}
27+
}
28+
if (x === m) {
29+
res.push(y);
30+
} else res.push(-1);
31+
}
32+
return res;
33+
}

0 commit comments

Comments
 (0)