Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- /*
- Problem Link: https://leetcode.com/problems/search-in-a-binary-search-tree/
- Language:
- Swift
- Params:
- root: Custom data(class) type;
- val: Int;
- Return:
- Custom data(class) type; return a class object.
- Complexity analysis:
- Space: O(Possible reached recursion depth) -> O(log n)
- Time: O(log n)
- */
- func searchBST(_ root: TreeNode?, _ val: Int) -> TreeNode? {
- if let curr_node = root {
- return curr_node.val == val ? curr_node : searchBST(curr_node.val >= val ? curr_node.left : curr_node.right, val)
- }
- return nil
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement