0651-0660

651. 4 Keys Keyboard \star\star

652. Find Duplicate Subtrees \star\star

653. Two Sum IV - Input is a BST \star

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
 public:
  bool findTarget(TreeNode* root, int k) {
    vector<int> nums;

    inorder(root, nums);

    int l = 0;
    int r = nums.size() - 1;

    while (l < r) {
      int sum = nums[l] + nums[r];
      if (sum == k) return true;
      if (sum < k)
        ++l;
      else
        --r;
    }

    return false;
  }

  void inorder(TreeNode* root, vector<int>& nums) {
    if (!root) return;

    inorder(root->left, nums);
    nums.push_back(root->val);
    inorder(root->right, nums);
  }
};

654. Maximum Binary Tree \star\star

655. Print Binary Tree \star\star

656. Coin Path \star\star\star

657. Robot Return to Origin \star

658. Find K Closest Elements \star\star

659. Split Array into Consecutive Subsequences \star\star

660. Remove 9 \star\star\star