Run Time Error! Where is the problem


  • 0
    K

    Here is my code

    static public boolean wordBreak(String s, Set<String> dict)
        {
            if(s.equals("") || dict.isEmpty())
                return false;
            if(dict.contains(s))
                return true;
            StringBuilder sc = new StringBuilder();
            
            int i=0;
               
            while(i<s.length())
            {
                sc.append(s.charAt(i)); 
                 if(dict.contains(sc.toString()))
                {
                        if(wordBreak(s.substring(i+1),dict)) 
                             return true;
                 }
                       i++;    
           }
        
            return false;
    
    }

  • 0
    K

    Sorry, the problem is Time Limit Exceeded, not Run Time Error


Log in to reply
 

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