File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
src/main/java/com/chen/algorithm/study Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .chen .algorithm .study .test24 ;
2
2
3
+ import org .junit .Test ;
4
+
3
5
/**
4
6
* 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。
5
7
* <p>
@@ -27,7 +29,6 @@ public ListNode swapPairs(ListNode head) {
27
29
ListNode firstNode = head ;
28
30
ListNode secondNode = head .next ;
29
31
30
-
31
32
firstNode .next = secondNode .next ;
32
33
secondNode .next = prev .next ;
33
34
prev .next = secondNode ;
@@ -40,4 +41,22 @@ public ListNode swapPairs(ListNode head) {
40
41
}
41
42
42
43
44
+ @ Test
45
+ public void test (){
46
+ ListNode l1_1 = new ListNode (1 );
47
+ ListNode l1_2 = new ListNode (2 );
48
+ ListNode l1_3 = new ListNode (3 );
49
+ ListNode l1_4 = new ListNode (4 );
50
+
51
+ l1_1 .next = l1_2 ;
52
+ l1_2 .next = l1_3 ;
53
+ l1_3 .next = l1_4 ;
54
+
55
+ ListNode result = swapPairs (l1_1 );
56
+
57
+ System .out .println (result .val );
58
+ System .out .println (result .next .val );
59
+ System .out .println (result .next .next .val );
60
+ System .out .println (result .next .next .next .val );
61
+ }
43
62
}
Original file line number Diff line number Diff line change 3
3
/**
4
4
* @author : chen weijie
5
5
* @Date: 2019-09-08 02:19
6
+ * @Description: zhunn 删除排序链表中的重复元素
6
7
*/
7
8
public class Solution2 {
8
9
You can’t perform that action at this time.
0 commit comments