Skip to content

Commit 1950ca1

Browse files
add 700
1 parent 24b915a commit 1950ca1

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ LeetCode
303303
|0684|[Redundant Connection](https://leetcode.com/problems/redundant-connection/) | c | [c++](./src/0684-Redundant-Connection/0684.cpp) |[python](./src/0684-Redundant-Connection/0684.py)|||||Medium|
304304
|0687|[Longest Univalue Path](https://leetcode.com/problems/redundant-connection/) | c | [c++](./src/0687-Longest-Univalue-Path/0687.cpp) |[python](./src/0687-Longest-Univalue-Path/0687.py)|||||Easy|
305305
|0695|[Max Area of Island](https://leetcode.com/problems/max-area-of-island/)|c|[c++](./src/0695-Max-Area-of-Island/0695.cpp)|[python](./src/0695-Max-Area-of-Island/0695.py)|[go](./src/0695-Max-Area-of-Island/0695.go)|[js](./src/0695-Max-Area-of-Island/0695.js)|[java](./src/0695-Max-Area-of-Island/0695.java)||Medium|
306-
|0697|[Degree of an Array](https://leetcode.com/problems/degree-of-an-array/)|c|[c++](./src/0697-Degree-of-an-Array/0697.cpp)|python|go|js|java||Easy|
306+
|0697|[Degree of an Array](https://leetcode.com/problems/degree-of-an-array/)||[c++](./src/0697-Degree-of-an-Array/0697.cpp)||||||Easy|
307307
|0698|[Partition to K Equal Sum Subsets](https://leetcode.com/problems/partition-to-k-equal-sum-subsets/)|c|[c++](./src/0698-Partition-to-K-Equal-Sum-Subsets/0698.cpp)|[python](./src/0698-Partition-to-K-Equal-Sum-Subsets/0698.py)|[go](./src/0698-Partition-to-K-Equal-Sum-Subsets/0698.go)|[js](./src/0698-Partition-to-K-Equal-Sum-Subsets/0698.js)|[java](./src/0698-Partition-to-K-Equal-Sum-Subsets/0698.java)||Medium|
308+
|0700|[Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree/)||[c++](./src/0700-Search-in-a-Binary-Search-Tree/0700.cpp)|||||[rust](./src/0700-Search-in-a-Binary-Search-Tree/0700.rs)|Easy|
308309
|0733|[Flood Fill](https://leetcode.com/problems/flood-fill/) | c | [c++](./src/0733-Flood-Fill/0733.cpp) |[python](./src/0733-Flood-Fill/0733.py)|||||Easy|
309310
|0739|[Daily Temperatures](https://leetcode.com/problems/daily-temperatures/) | c | [c++](./src/0739-Daily-Temperatures/0739.cpp) |[python](./src/0739-Daily-Temperatures/0739.py)|||||Medium|
310311
|0742|[Closest Leaf in a Binary Tree](https://leetcode.com/problems/closest-leaf-in-a-binary-tree/) | c | [c++](./src/0742-Closest-Leaf-in-a-Binary-Tree/0742.cpp) |[python](./src/0742-Closest-Leaf-in-a-Binary-Tree/0742.py)|||||Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
TreeNode *searchBST(TreeNode *root, int val) {
4+
if (root == nullptr) {
5+
return nullptr;
6+
}
7+
if (val == root->val) {
8+
return root;
9+
}
10+
return searchBST(val < root->val ? root->left : root->right, val);
11+
}
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::cell::RefCell;
2+
use std::cmp::Ordering;
3+
use std::rc::Rc;
4+
impl Solution {
5+
pub fn search_bst(
6+
root: Option<Rc<RefCell<TreeNode>>>,
7+
val: i32,
8+
) -> Option<Rc<RefCell<TreeNode>>> {
9+
if let Some(t) = root {
10+
let v = t.borrow().val;
11+
match v.cmp(&val) {
12+
Ordering::Equal => Some(t),
13+
Ordering::Greater => Self::search_bst(t.borrow_mut().left.take(), val),
14+
Ordering::Less => Self::search_bst(t.borrow_mut().right.take(), val),
15+
}
16+
} else {
17+
None
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)