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

Commit9bb1d5f

Browse files
refactor 25
1 parent98f2363 commit9bb1d5f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

‎src/main/java/com/fishercoder/solutions/_25.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
publicclass_25 {
66

7-
/**We use recursion to go all the way until the end: when the number of nodes are smaller than k;
8-
* then we start to reverse each group of k nodes from the end towards the start.*/
7+
/**
8+
* We use recursion to go all the way until the end: when the number of nodes are smaller than k;
9+
* then we start to reverse each group of k nodes from the end towards the start.
10+
*/
911
publicstaticclassSolution1 {
1012
publicListNodereverseKGroup(ListNodehead,intk) {
1113
ListNodecurr =head;
@@ -44,16 +46,16 @@ public ListNode reverseKGroup(ListNode head, int k) {
4446
intn =0;// number of nodes
4547

4648
ListNodecurr =head;
47-
while(curr !=null){
48-
n++;
49+
while(curr !=null){
50+
n++;
4951
curr =curr.next;
5052
}
5153

5254
ListNodeprev =null;
5355
ListNodenext =null;
5456
ListNodenewHead =null;
5557
ListNodetail1 =null;
56-
ListNodetail2 =head;
58+
ListNodetail2 =head;
5759

5860
curr =head;
5961

‎src/test/java/com/fishercoder/_25Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void test1() {
2828
expected =LinkedListUtils.contructLinkedList(newint[]{2,1,4,3,5});
2929
assertEquals(actual,expected);
3030
}
31+
3132
@Test
3233
publicvoidtest2() {
3334
head =LinkedListUtils.contructLinkedList(newint[]{1,2,3,4,5,6,7});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp