Skip to content

Commit 9bb1d5f

Browse files
refactor 25
1 parent 98f2363 commit 9bb1d5f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
public class _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
public static class Solution1 {
1012
public ListNode reverseKGroup(ListNode head, int k) {
1113
ListNode curr = head;
@@ -44,16 +46,16 @@ public ListNode reverseKGroup(ListNode head, int k) {
4446
int n = 0; // number of nodes
4547

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

5254
ListNode prev = null;
5355
ListNode next = null;
5456
ListNode newHead = null;
5557
ListNode tail1 = null;
56-
ListNode tail2 = head;
58+
ListNode tail2 = head;
5759

5860
curr = head;
5961

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

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void test1() {
2828
expected = LinkedListUtils.contructLinkedList(new int[]{2, 1, 4, 3, 5});
2929
assertEquals(actual, expected);
3030
}
31+
3132
@Test
3233
public void test2() {
3334
head = LinkedListUtils.contructLinkedList(new int[]{1, 2, 3, 4, 5, 6, 7});

0 commit comments

Comments
 (0)