1 public class Solution {
2 public boolean isMatch(String s, String p) {
3 // IMPORTANT: Please reset any member data you declared, as
4 // the same Solution instance will be reused for each test case.
5 if(p == null||p.length() == 0) return s == null||s.length()==0;
6 if(p.length() < 2 || p.charAt(1) != '*')
7 {
8 if((s.length() > 0 && p.length() > 0 && p.charAt(0) == s.charAt(0)) || (p.charAt(0) == '.' && s.length() != 0))
9 {
10 return isMatch(s.substring(1), p.substring(1));
11 }
12 return false;
13 }
14 else
15 {
16 while((s.length() > 0 && p.length() > 0 && p.charAt(0) == s.charAt(0)) || (p.charAt(0) == '.' && s.length() != 0))
17 {
18 if(isMatch(s, p.substring(2)))
19 {
20 return true;
21 }
22 s = s.substring(1);
23 }
24 return isMatch(s, p.substring(2));
25
26 }
27 }
28 }