We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 30d868f commit 3423008Copy full SHA for 3423008
scripts/algorithms/W/Where Will the Ball Fall/Where Will the Ball Fall.java
@@ -1,26 +1,27 @@
1
+// Runtime: 1 ms (Top 93.85%) | Memory: 54.4 MB (Top 47.92%)
2
class Solution {
3
public int dfs(int[][] grid, int i, int j){
4
if(i==grid.length)
5
return j;
-
6
+
7
if(j<0 || j>=grid[0].length)
8
return -1;
9
10
if(grid[i][j]==1 && j+1<grid[0].length && grid[i][j+1]==1)
11
return dfs(grid,i+1,j+1);
12
13
else if(grid[i][j]==-1 && j-1>=0 && grid[i][j-1]==-1)
14
return dfs(grid,i+1,j-1);
15
16
17
}
18
public int[] findBall(int[][] grid) {
19
int m = grid[0].length;
20
int[] ar = new int[m];
21
22
for(int j=0;j<m;j++)
23
ar[j]=dfs(grid,0,j);
24
25
return ar;
26
-}
27
+}
0 commit comments