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

Commitc482529

Browse files
authored
Merge pull requestneetcode-gh#361 from Chrislee1996/main
Created 235-lowest-common-ancestor-of-a-BST and 66-Plus-One for Javascript
2 parents96d23fe +12fdcd4 commitc482529

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-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+
};

‎javascript/66-plus-one.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
*@param {number[]} digits
3+
*@return {number[]}
4+
*/
5+
varplusOne=function(digits){
6+
for(leti=digits.length-1;i>=0;i--){
7+
if(digits[i]!==9){
8+
digits[i]++
9+
returndigits
10+
}else{
11+
digits[i]=0
12+
}
13+
}
14+
digits.unshift(1)
15+
returndigits
16+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp