public class Solution {
    public boolean isMatch(String s, String p) {
    	if(p.equals(".*") || s.length() == 0){
    		return true;
    	}else if(p.length() == 0){
    	    return false;
    	}

    	int sLen = s.length();
    	int pLen = p.length();
    	boolean[][] dp = new boolean[sLen][pLen];

    	if(s.charAt(0) == p.charAt(0) || p.charAt(0) == '.'){
    		dp[0][0] = true;
    	}
    	

    	for(int i = 0; i < sLen; i++){
    		for(int j = 0; j < pLen; j++){
    			if( j == 0){
    				continue;
    			}

    			boolean conditionOne = (p.charAt(j - 1) == s.charAt(i) && p.charAt(j) == '*') || (p.charAt(j - 1) == '*' && p.charAt(j) == s.charAt(i));

    			if(i == 0){
    				if(conditionOne){
    					dp[i][j] = true;
    				}
    				continue;
    			}

    			boolean	charMatch = s.charAt(i) == p.charAt(j) || p.charAt(j) == '.';
    			boolean conditionTwo = dp[i - 1][j - 1] && charMatch;
    			dp[i][j] = conditionTwo || conditionOne;
    		}
    	}

    	return dp[sLen - 1][pLen - 1];
	}
}
@@ -69,86 +69,160 @@
 p) %7B
+ 
 %0A    
-%09if(p.equals(%22.*%22) %7C%7C s.length() == 0)%7B
+    return matchHelper(s, p, 0, 0);
 %0A    
-%09%09return true;%0A    %09%7Delse
+%7D%0A    %0A    public boolean matchHelper(String s, String p, int sIndex, int pIndex) %7B%0A       
  if
+ 
 (
+pIndex == 
 p.le
@@ -227,29 +227,28 @@
 length()
- == 0)%7B%0A
+) %7B%0A  
     
-%09
+  
     retu
@@ -254,66 +254,61 @@
 urn 
-false;%0A    %09%7D%0A%0A    %09int sLen = s.length();%0A    %09int pLen
+sIndex == s.length();%0A        %7D%0A        if (pIndex
  =
+=
  p.l
@@ -318,75 +318,73 @@
 th()
-;%0A    %09boolean%5B%5D%5B%5D dp = new boolean%5BsLen%5D%5BpLen%5D;%0A%0A    %09if(s
+ - 1) %7B%0A            return sIndex == s.length() - 1 && (p
 .charAt(
 0) =
@@ -383,23 +383,28 @@
 rAt(
-0
+pIndex
 ) == 
-p
+s
 .charAt(
 0) %7C
@@ -399,17 +399,22 @@
 .charAt(
-0
+sIndex
 ) %7C%7C p.c
@@ -419,17 +419,22 @@
 .charAt(
-0
+pIndex
 ) == '.'
@@ -438,197 +438,188 @@
 '.')
-%7B
+;
 %0A    
-%09%09dp%5B0%5D%5B0%5D = true;%0A    %09
+    
 %7D%0A    
-%09%0A%0A
     
-%09for(int i = 0; i %3C sLen; i++)%7B%0A    %09%09for(int j = 0; j %3C pLen; j++)%7B%0A    %09%09%09if( j == 0)%7B%0A    %09%09%09%09continue;%0A    %09%09%09%7D%0A%0A    %09%09%09boolean conditionOne =
+if (pIndex + 1 %3C p.length() && p.charAt(pIndex + 1) != '*') %7B%0A            if (sIndex == s.length()) %7B%0A                return false;%0A            %7D%0A            if
  (p.
@@ -621,29 +621,30 @@
 f (p.charAt(
-j - 1
+pIndex
 ) == s.charA
@@ -649,13 +649,18 @@
 rAt(
-i) &&
+sIndex) %7C%7C
  p.c
@@ -669,224 +669,337 @@
 rAt(
-j
+pIndex
 ) == '
-*') %7C%7C (p.charAt(j - 1) == '*' && p.charAt(j) == s.charAt(i)
+.') %7B%0A                return matchHelper(s, p, sIndex + 1, pIndex + 1
 );%0A
-%0A
     
-%09%09%09if(i == 0)%7B%0A    %09%09%09%09if(conditionOne)%7B%0A    %09%09%09%09%09dp%5Bi%5D%5Bj%5D = tru
+        %7D else %7B%0A                return fals
 e;%0A    
-%09%09%09%09%7D%0A    %09%09%09%09continue;%0A    %09%09%09%7D%0A%0A    %09%09%09boolean%09charMatch = s
+        %7D%0A        %7D else %7B%0A            // try to cover all chars in s that can be matched by first two chars in p%0A            while ( sIndex %3C s.length() && pIndex %3C p.length() && (p
 .charAt(
 i) =
@@ -998,23 +998,28 @@
 rAt(
-i
+pIndex
 ) == 
-p
+s
 .charAt(
 j) %7C
@@ -1014,17 +1014,22 @@
 .charAt(
-j
+sIndex
 ) %7C%7C p.c
@@ -1038,17 +1038,22 @@
 rAt(
-j
+pIndex
 ) == '.'
 ;%0A  
@@ -1052,171 +1052,259 @@
  '.'
-;%0A    %09%09%09boolean conditionTwo = dp%5Bi - 1%5D%5Bj - 1%5D && charMatch;%0A    %09%09%09dp%5Bi%5D%5Bj%5D = conditionTwo %7C%7C conditionOne;%0A    %09%09%7D%0A    %09%7D%0A%0A    %09return dp%5BsLen - 1%5D%5BpLen - 1%5D;%0A%09%7D%0A%7D
+ )) %7B%0A                if (matchHelper(s, p, sIndex, pIndex + 2)) %7B%0A                    return true;%0A                %7D%0A                sIndex++;%0A            %7D%0A            %0A            return matchHelper(s, p, sIndex, pIndex + 2);%0A        %7D%0A    %7D%0A%7D%0A        

update regular expression matching solution