You are viewing a single comment's thread. Return to all comments →
My code works for all test cases, including yours.
private static boolean search(int[][] grid, int[][] pattern) { int hGrid = grid.length; int wGrid = grid[0].length; int hPat = pattern.length; int wPat = pattern[0].length; int wG = 0; boolean patternCompletelyFound = false; while (wG + wPat <= wGrid && patternCompletelyFound == false) { boolean matching = false; int hp = 0; for (int hG = 0; hG < hGrid; hG++) { if (!matching && hGrid - hG < hPat) { break; } if (hPat == hp) { break; } if (match(grid[hG], pattern[hp], wG) || match(grid[hG], pattern[0], wG) ) { hp++; matching = true; } else { matching = false; hp = 0; } } if (matching == true && hPat == hp) { patternCompletelyFound = true; } wG++; } return patternCompletelyFound; } private static boolean match( int[] gridLine, int[] patLine, int wG) { boolean matched = true; for (int i = 0; i<patLine.length; i++) { //System.out.println("grid: " + gridLine[i + wG] + " pat: " + patLine[i]); if (patLine[i] != gridLine[i + wG]) { matched = false; break; } } return matched; }
The Grid Search
You are viewing a single comment's thread. Return to all comments →
My code works for all test cases, including yours.