1 class Solution 2 { 3 public: 4 int f(TreeNode* root) 5 { 6 if(!root) return 0; 7 return f(root->left)+f(root->right)+1; 8 } 9 TreeNode* preorder(TreeNode *root,int x) 10 { 11 if(!root) return NULL; 12 if(root->val==x) 13 return root; 14 TreeNode *t1 = preorder(root->left,x); 15 TreeNode *t2 = preorder(root->right,x); 16 if(t1) return t1; 17 else if(t2) return t2; 18 return NULL; 19 } 20 bool btreeGameWinningMove(TreeNode* root, int n, int x) 21 { 22 TreeNode* t = preorder(root,x); 23 int k1 = f(t->left); 24 int k2 = f(t->right); 25 if(max(2*k1,2*k2)>n || n>2*(k1+k2+1)) 26 return true; 27 return false; 28 } 29 };