1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public: bool sumGame(string num) { int n = num.size(); int a = 0, b = 0, ax = 0, bx = 0; for (int i = 0; i < n / 2; ++i) if (num[i] == '?') ++ax; else a += num[i] - '0'; for (int i = n / 2; i < n; ++i) if (num[i] == '?') ++bx; else b += num[i] - '0'; int x = ax + bx; if (x & 1) return true; int xa = (ax + 1) / 2, xb = x / 2 - xa, ya = ax - xa, yb = bx - xb; if (ya * 9 + a < xb * 9 + b) return true; if (xa * 9 + a > yb * 9 + b) return true; return false; } };
|