eng.reemmohammed
BAN USERclass Solution {
public boolean calculatePath(int [][] matrix){
if(matrix == null || matrix.length == 0){
return false;
}
Queue <int[]> queue = new LinkedList<>();
int [][] directions = {{0, 1} ,{1 , 0} };
queue.add(new int [] {0 , 0});
while(!queue.isEmpty()){
int [] arr = queue.poll();
int row = arr[0];
int col = arr[1];
if(row == matrix.length - 1 && col == matrix[0].length -1){
return true;
}
for(int [] dir : directions){
int x = row + dir[0];
int y = col + dir[1];
if(x < matrix.length && y < matrix[0].length && matrix[x][y] == 1){
queue.add(new int[] {x , y});
}
}
}
return false;
}
- eng.reemmohammed July 08, 2021