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

Commit07f12cf

Browse files
Merge pull requestneetcode-gh#3064 from benmak11/708
Create 0708-insert-into-a-sorted-circular-linked-list.java
2 parentsaf22904 +cfdc7df commit07f12cf

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+
classSolution {
2+
publicNodeinsert(Nodehead,intinsertVal) {
3+
Nodenode =newNode(insertVal);
4+
if (head ==null) {
5+
node.next =node;
6+
returnnode;
7+
}
8+
Nodeprev =head,curr =head.next;
9+
while (curr !=head) {
10+
if ((prev.val <=insertVal &&insertVal <=curr.val)
11+
|| (prev.val >curr.val && (insertVal >=prev.val ||insertVal <=curr.val))){
12+
break;
13+
}
14+
prev =curr;
15+
curr =curr.next;
16+
}
17+
prev.next =node;
18+
node.next =curr;
19+
returnhead;
20+
}
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp