Skip to content

Commit e6028d0

Browse files
committed
modify code
1 parent 688e979 commit e6028d0

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/class04/Code01_ReverseList.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ public static boolean checkDoubleListReverse(List<Integer> origin, DoubleNode he
175175
return true;
176176
}
177177

178+
179+
public static void f(Node head) {
180+
head = head.next;
181+
}
182+
178183
// for test
179184
public static void main(String[] args) {
180185
int len = 50;

src/class04/Code04_ReverseNodesInKGroup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ public static ListNode reverseKGroup(ListNode head, int k) {
1515
if (end == null) {
1616
return head;
1717
}
18+
// 第一组凑齐了!
1819
head = end;
1920
reverse(start, end);
21+
// 上一组的结尾节点
2022
ListNode lastEnd = start;
2123
while (lastEnd.next != null) {
2224
start = lastEnd.next;

src/class04/Code05_AddTwoNumbers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static ListNode addTwoNumbers(ListNode head1, ListNode head2) {
4949
return l;
5050
}
5151

52+
// 求链表长度
5253
public static int listLength(ListNode head) {
5354
int len = 0;
5455
while (head != null) {

src/class04/Code06_MergeTwoSortedLinkedList.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public static class ListNode {
99
public ListNode next;
1010
}
1111

12-
public static ListNode mergeTwoLists(ListNode l1, ListNode l2) {
13-
if (l1 == null || l2 == null) {
14-
return l1 == null ? l2 : l1;
12+
public static ListNode mergeTwoLists(ListNode head1, ListNode head2) {
13+
if (head1 == null || head2 == null) {
14+
return head1 == null ? head2 : head1;
1515
}
16-
ListNode head = l1.val <= l2.val ? l1 : l2;
16+
ListNode head = head1.val <= head2.val ? head1 : head2;
1717
ListNode cur1 = head.next;
18-
ListNode cur2 = head == l1 ? l2 : l1;
18+
ListNode cur2 = head == head1 ? head2 : head1;
1919
ListNode pre = head;
2020
while (cur1 != null && cur2 != null) {
2121
if (cur1.val <= cur2.val) {

0 commit comments

Comments
 (0)