0331-0340

331. Verify Preorder Serialization of a Binary Tree $\star\star$

332. Reconstruct Itinerary $\star\star$

333. Largest BST Subtree $\star\star$

334. Increasing Triplet Subsequence $\star\star$

335. Self Crossing $\star\star\star$

336. Palindrome Pairs $\star\star\star$

337. House Robber III $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class Solution {
 public:
  int rob(TreeNode* root) {
    vector<int> ans = helper(root);

    return max(ans[0], ans[1]);
  }

  vector<int> helper(TreeNode* root) {
    if (!root) return {0, 0};

    vector<int> left = helper(root->left);
    vector<int> right = helper(root->right);

    return {max(left[0], left[1]) + max(right[0], right[1]),
            root->val + left[0] + right[0]};
  }
};

338. Counting Bits $\star\star$

339. Nested List Weight Sum $\star$

340. Longest Substring with At Most K Distinct Characters $\star\star\star$