leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1145.cpp (463B)
0 class Solution {
1 mutable int left, right, val;
3 int count(const TreeNode *node) const {
4 if (!node) return 0;
5 int l = count(node->left), r = count(node->right);
6 if (node->val == val) left = l, right = r;
7 return l + r + 1;
8 }
10 public:
11 bool btreeGameWinningMove(const TreeNode *root, int n, int x) const {
12 val = x, n = count(root);
13 return max(max(left, right), n - left - right - 1) > n / 2;
14 }
15 };