public class Solution { public boolean isMatch(String s, String p) { int sLen = s.length(), pLen = p.length(); int i = 0, j = 0; int ss = 0, starP = -1; while (i < sLen) { while(j < pLen && p.charAt(j) == ‘*‘){ starP = j++; ss = i; } if((j == pLen) || (s.charAt(i) != p.charAt(j) && p.charAt(j) != ‘?‘)){ if(starP < 0){ return false; } else { j = starP + 1; i = ++ss; } } else{ i++; j++; } } while (j < pLen && p.charAt(j) == ‘*‘) { j++; } return j == pLen; } }
原文:http://www.cnblogs.com/RazerLu/p/3531139.html