code: public int search(String text) {
  
          // Searching
          int i = pattern.length() - 1;
          int j = pattern.length() - 1;
          while (i < text.length()) {
              if (pattern.charAt(j) == text.charAt(i)) {
                  if (j == 0) {
                      //the left-most match is found
                      return i;
                  }
                  j--;
                  i--;
              } else { //a difference
                  i += pattern.length() - j - 1 + Math.max(j - last[text.charAt(i)], match[j]);
                  j = pattern.length() - 1;
              }
          }
          return -1;
      }
docs: Searching the pattern in the text
  @param text the text to search the pattern
  @return -1 if the pattern was not found, location of the pattern if it was found.