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

Commit 8c1dd85

Browse files
Update Solution2.java
1 parent 2a24eb3 commit 8c1dd85

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

‎solution/0061.Rotate List/Solution2.java‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@
88
*/
99
class Solution {
1010
public ListNode rotateRight(ListNode head, int k) {
11-
if (head == null) return head;
12-
if (head.next == null) return head;
11+
if (head == null)
12+
return head;
13+
if (head.next == null)
14+
return head;
1315

1416
int size = 1;
1517
// build ring
1618
ListNode nodeLast = head;
17-
while (nodeLast.next!=null) {
19+
while (nodeLast.next != null) {
1820
nodeLast = nodeLast.next;
1921
size++;
2022
}
2123
nodeLast.next = head;
2224

2325
// cutting
24-
k = size-k%size;
25-
while (k-->0){
26+
k = size - k % size;
27+
while (k-- > 0) {
2628
nodeLast = head;
2729
head = head.next;
2830
}
2931
nodeLast.next = null;
3032
return head;
3133
}
32-
}
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /