File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 89
89
648|[ Replace Words] ( ./0648-replace-words.js ) |Medium|
90
90
653|[ Two Sum IV - Input is a BST] ( ./0653-two-sum-iv---input-is-a-bst.js ) |Easy|
91
91
686|[ Repeated String Match] ( ./0686-repeated-string-match.js ) |Easy|
92
+ 700|[ Search in a Binary Search Tree] ( ./0700-search-in-a-binary-search-tree.js ) |Easy|
92
93
701|[ Insert into a Binary Search Tree] ( ./0701-insert-into-a-binary-search-tree.js ) |Medium|
93
94
713|[ Subarray Product Less Than K] ( ./0713-subarray-product-less-than-k.js ) |Medium|
94
95
722|[ Remove Comments] ( ./0722-remove-comments.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 700. Search in a Binary Search Tree
3
+ * https://leetcode.com/problems/search-in-a-binary-search-tree/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given the root of a binary search tree (BST) and an integer val.
7
+ *
8
+ * Find the node in the BST that the node's value equals val and return the
9
+ * subtree rooted with that node. If such a node does not exist, return null.
10
+ */
11
+
12
+ /**
13
+ * Definition for a binary tree node.
14
+ * function TreeNode(val, left, right) {
15
+ * this.val = (val===undefined ? 0 : val)
16
+ * this.left = (left===undefined ? null : left)
17
+ * this.right = (right===undefined ? null : right)
18
+ * }
19
+ */
20
+ /**
21
+ * @param {TreeNode } root
22
+ * @param {number } val
23
+ * @return {TreeNode }
24
+ */
25
+ var searchBST = function ( root , val ) {
26
+ while ( root ) {
27
+ if ( root . val === val ) {
28
+ return root ;
29
+ }
30
+ root = root . val > val ? root . left : root . right ;
31
+ }
32
+
33
+ return null ;
34
+ } ;
You can’t perform that action at this time.
0 commit comments