Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd3e3e53

Browse files
committed
Created 235-lowest-common-ancestor-of-a-BST-Javascript
1 parent65b8987 commitd3e3e53

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
9+
/**
10+
*@param {TreeNode} root
11+
*@param {TreeNode} p
12+
*@param {TreeNode} q
13+
*@return {TreeNode}
14+
*/
15+
varlowestCommonAncestor=function(root,p,q){
16+
while(root!==null){
17+
if(root.val<p.val&&root.val<q.val){
18+
root=root.right
19+
}elseif(root.val>p.val&&root.val>q.val){
20+
root=root.left
21+
}else{
22+
returnroot
23+
}
24+
}
25+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp