You are viewing a single comment's thread. Return to all comments →
public static List<String> cavityMap(List<String> grid) { int n = grid.size(); char[][] charGrid = new char[n][n];//2D char array for(int i = 0;i<n;i++){ charGrid[i] = grid.get(i).toCharArray(); } for(int i=1;i<n-1;i++){ for(int j=1;j<n-1;j++){ //only inside grid,not boundaries int current = charGrid[i][j]; if(charGrid[i][j-1]<current && charGrid[i][j+1]<current && charGrid[i-1][j]<current && charGrid[i+1][j]<current){ charGrid[i][j] = 'X'; } } } List<String> ans = new ArrayList<>(); for(int i=0;i<n;i++){ ans.add(String.valueOf(charGrid[i])); } return ans; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cavity Map
You are viewing a single comment's thread. Return to all comments →