Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. private static boolean matches(String s, String p, int sIndex, int pIndex) {
  2.         if (sIndex == s.length() || pIndex == p.length()) {
  3.             return true;
  4.         }
  5.         if (p.toCharArray()[pIndex] == '*' && sIndex == s.length()
  6.                 && pIndex != p.length()) {
  7.             return false;
  8.         }
  9.         if (p.toCharArray()[pIndex] == '?') {
  10.             return matches(s, p, ++sIndex, ++pIndex);
  11.         } else if (s.toCharArray()[sIndex] == p.toCharArray()[pIndex]) {
  12.             return matches(s, p, ++sIndex, ++pIndex);
  13.         } else if (p.toCharArray()[pIndex] == '*') {
  14.             return matches(s, p, ++sIndex, pIndex)
  15.                     || matches(s, p, ++sIndex, ++pIndex);
  16.         } else {
  17.             return false;
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement