We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 12ed6eb commit 05600caCopy full SHA for 05600ca
lowest-common-ancestor-of-a-binary-search-tree/nhistory.js
@@ -0,0 +1,11 @@
1
+var lowestCommonAncestor = function (root, p, q) {
2
+ // Iterate if statement with comparing values
3
+ while (root) {
4
+ if (root.val < p.val && root.val < q.val) root = root.right;
5
+ else if (root.val > p.val && root.val > q.val) root = root.left;
6
+ else return root;
7
+ }
8
+};
9
+
10
+// TC: O(n)
11
+// SC: O(1)
0 commit comments