1class Solution {2public boolean sumGame(String num) {3int q = 0, d = 0, n = num.length();4for (int i = 0; i < n; i++) {5if (num.charAt(i) == '?') {6q += 2 * i < n ? 1 : -1;7} else {8d += (2 * i < n ? 1 : -1) * (num.charAt(i) - '0');9}10}11return (q & 1) > 0 || q * 9 + 2 * d != 0;12}13}