You are viewing a single comment's thread. Return to all comments →
Java solution
public static boolean checkPattern(List<String> G, List<String> P, int start_i, int start_j){ int R = G.size(); int C = G.get(0).length(); int r = P.size(); int c = P.get(0).length(); int end_i = start_i + (r-1); int end_j = start_j + (c-1); if(end_i >= R || end_j >= C) return false; for(int i = 0; i < r; i++) for(int j = 0; j < c; j++){ char pattern_num = P.get(i).charAt(j); char grid_num = G.get(i + start_i).charAt(j + start_j); if(grid_num != pattern_num) return false; } return true; } public static String gridSearch(List<String> G, List<String> P) { int R = G.size(); int C = G.get(0).length(); char first_pattern_num = P.get(0).charAt(0); for(int i = 0; i < R; i++) for(int j = 0; j < C; j++){ char grid_num = G.get(i).charAt(j); if(grid_num == first_pattern_num && checkPattern(G,P,i,j) ) return "YES"; } return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Grid Search
You are viewing a single comment's thread. Return to all comments →
Java solution