AC Cpp solution, convert "++"--> "-"


  • 0
    G
    class Solution {
    public:
    	bool canWin(string s)
    	{
    		int size = s.size();
    		if (size < 2) return false;
    
    		if (size == 2)
    		{
    			if (s == "++") return true;
    			return false;
    		}
    
    		if (size == 3)
    		{
    			if (s == "++-" || s == "-++" || s=="+++") return true;
    			return false;
    		}
    
    		for (int i = 0; i < s.size() - 1; i++)
    		{
    			if (s[i] == '+' && s[i + 1] == '+')
    			{
    				string t1 = s.substr(0, i);
    				string t2 = s.substr(i + 2, s.size() - i - 2);
    				string t = t1 + "-" + t2;
    				bool b = canWin(t);
    				if (!b) return true;
    			}
    		}
    
    		return false;
    	}
    };

  • 0
    G
    This post is deleted!

Log in to reply
 

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