题目:
实现:
class Solution { public boolean isMatch(String s, String p) { if(s==null||p==null) return false; char[] sc = s.toCharArray(); char[] pc = p.toCharArray(); return toMatch(sc,pc,0,0); } public static boolean toMatch(char[] s,char[] p,int i,int j){ int n = s.length; int m = p.length; if(j>=m) return i==n; boolean j_match=i<n&&(s[i]==p[j] || p[j]=='.'); if(j+1<m&&p[j+1]=='*'){ return toMatch(s,p,i,j+2)||(j_match&&toMatch(s,p,i+1,j)); } return j_match&&toMatch(s,p,i+1,j+1); } }