You are viewing a single comment's thread. Return to all comments →
public static List<String> cavityMap(List<String> grid) { List<String> result = new ArrayList<>(); result.add(grid.get(0)); for(int i = 1; i < grid.size() - 1; i++) { String temp = ""; char topRow[] = grid.get(i - 1).toCharArray(); char curRow[] = grid.get(i).toCharArray(); char bottomRow[] = grid.get(i + 1).toCharArray(); // border temp += String.valueOf(curRow[0]); for(int j = 1; j < curRow.length - 1; j++) { char top = topRow[j]; char left = curRow[j - 1]; char current = curRow[j]; char right = curRow[j + 1]; char bottom = bottomRow[j]; if(current > left && current > right && current > top && current > bottom) { temp += "X"; } else { temp += String.valueOf(current); } } // border temp += String.valueOf(curRow[curRow.length - 1]); result.add(temp); } if(grid.size() > 1) { result.add(grid.get(grid.size() - 1)); } return result; }
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 →