1145.cpp (463B)
1 class Solution { 2 mutable int left, right, val; 3 4 int count(const TreeNode *node) const { 5 if (!node) return 0; 6 int l = count(node->left), r = count(node->right); 7 if (node->val == val) left = l, right = r; 8 return l + r + 1; 9 } 10 11 public: 12 bool btreeGameWinningMove(const TreeNode *root, int n, int x) const { 13 val = x, n = count(root); 14 return max(max(left, right), n - left - right - 1) > n / 2; 15 } 16 };