-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path294.cpp
25 lines (25 loc) · 850 Bytes
/
294.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
__________________________________________________________________________________________________
class Solution {
public:
bool canWin(string s) {
for (int i = 1; i < s.size(); ++i) {
if (s[i] == '+' && s[i - 1] == '+' && !canWin(s.substr(0, i - 1) + "--" + s.substr(i + 1))) {
return true;
}
}
return false;
}
};
__________________________________________________________________________________________________
class Solution {
public:
bool canWin(string s) {
for (int i = -1; (i = s.find("++", i + 1)) >= 0;) {
if (!canWin(s.substr(0, i) + "--" + s.substr(i + 2))) {
return true;
}
}
return false;
}
};
__________________________________________________________________________________________________