Can someone let me know the test cases being failed.


  • 0
    U

    public class Solution {
    public boolean isMatch(String s, String p) {

        if(s.length() == 0 && p.length() == 0 )
            return true;
    
        if(s.length() == 0 || p.length() == 0 )
            return false;
    
        if(p.length() == 1) {
            if(s.length() == 1 )
                return s.charAt(0) == p.charAt(0) || p.charAt(0) == '.';
            else
                return false;
        }
        
        if( p.charAt(1) == '*' )
        {
            //Zero Matches
            boolean ret = isMatch(s,p.substring(2));
            if( ret )
                return ret;
                
            //1 or more matches
            int i = 0;
            while( i < s.length() ) {
                if( p.charAt(0) == s.charAt(i) || p.charAt(0) == '.' ) {
                    ret = isMatch(s.substring(i+1),p.substring(2));
                if( ret )
                    return ret;
                } else {
                    break;
                }
            }
            
            return false;
        }
        else {
            if( p.charAt(0) == s.charAt(0) || p.charAt(0) == '.' ) {
                return isMatch(s.substring(1),p.substring(1));
            }
            else 
                return false;
        }
             
        
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.