bool btreeGameWinningMove(TreeNode* root, int n, int x) {
TreeNode *node = search(root, x);
int leftNum = getNodeNum(node->left);
int rightNum = getNodeNum(node->right);
int upNum = n - 1 - leftNum - rightNum;
int maxNum = max(max(leftNum, rightNum), upNum);
// cout << leftNum << endl;
// cout << rightNum << endl;
// cout << upNum << endl;
// cout << maxNum << endl;
return maxNum > (n - maxNum);
int getNodeNum(TreeNode *root) {
return 1 + getNodeNum(root->left) + getNodeNum(root->right);
TreeNode *search(TreeNode *root, int x) {
if (!root || root->val == x) return root;
TreeNode *node = search(root->left, x);
return search(root->right, x);