File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 80
80
| 561 | [ Array Partition I] ( https://leetcode.com/problems/array-partition-i/ ) | [ C] ( ./src/561.c ) | Easy |
81
81
| 617 | [ Merge Two Binary Trees] ( https://leetcode.com/problems/merge-two-binary-trees/ ) | [ C] ( ./src/617.c ) | Easy |
82
82
| 647 | [ Palindromic Substring] ( https://leetcode.com/problems/palindromic-substrings/ ) | [ C] ( ./src/647.c ) | Medium |
83
+ | 669 | [ Trim a Binary Search Tree] ( https://leetcode.com/problems/trim-a-binary-search-tree/ ) | [ C] ( ./src/669.c ) | Medium |
83
84
| 674 | [ Longest Continuous Increasing Subsequence] ( https://leetcode.com/problems/longest-continuous-increasing-subsequence/ ) | [ C] ( ./src/674.c ) | Easy |
84
85
| 700 | [ Search in a Binary Search Tree] ( https://leetcode.com/problems/search-in-a-binary-search-tree/ ) | [ C] ( ./src/700.c ) | Easy |
85
86
| 701 | [ Insert into a Binary Search Tree] ( https://leetcode.com/problems/insert-into-a-binary-search-tree/ ) | [ C] ( ./src/701.c ) | Medium |
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * struct TreeNode {
4
+ * int val;
5
+ * struct TreeNode *left;
6
+ * struct TreeNode *right;
7
+ * };
8
+ */
9
+
10
+
11
+ // Depth-First Search
12
+ // Runtime: O(n)
13
+ // Space: O(1)
14
+ struct TreeNode * trimBST (struct TreeNode * root , int low , int high ){
15
+ if (root == NULL ){
16
+ return NULL ;
17
+ }
18
+
19
+ if (root -> val > high ){
20
+ return trimBST (root -> left , low , high );
21
+ }
22
+
23
+ if (root -> val < low ){
24
+ return trimBST (root -> right , low , high );
25
+ }
26
+
27
+ root -> left = trimBST (root -> left , low , high );
28
+ root -> right = trimBST (root -> right , low , high );
29
+ return root ;
30
+ }
You can’t perform that action at this time.
0 commit comments