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

Commit9b78240

Browse files
authored
add 230-Kth-Smallest-Element-in-a-BST
1 parent8c2b30a commit9b78240

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
functionkthSmallest(root,k){
2+
letn=0;
3+
conststack=[];
4+
letcur=root;
5+
6+
while(cur||stack){
7+
while(cur){
8+
stack.push(cur);
9+
cur=cur.left;
10+
}
11+
12+
cur=stack.pop();
13+
n+=1;
14+
15+
if(n==k){
16+
returncur.val;
17+
}
18+
19+
cur=cur?.right;
20+
}
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp