• + 0 comments

    Java

      public static String gridSearch(List<String> G, List<String> P) {
        for (int i = 0; i <= G.size() - P.size(); i++) {
          int index = G.get(i).indexOf(P.get(0));
          while (index != -1) {
            boolean match = true;
            for (int j = 1; j < P.size(); j++) {
              if (!G.get(i + j).substring(index, index + P.get(0).length()).equals(P.get(j))) {
                match = false;
                break;
              }
            }
            if (match) return "YES";
            index = G.get(i).indexOf(P.get(0), index + 1);
          }
        }
        return "NO";
      }