10-line java ac backtracking solution


  • 0
    A
    public boolean canWin(String s) { 
        for (int i = 0; i < s.length() - 1; i++) {
            if (s.startsWith("++", i)) {
                String t = s.substring(0, i) + "--" + s.substring(i + 2);      
                if (!canWin(t))  return true;   
            }
        }    
        return false;
    }

Log in to reply
 

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