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 11package com .chen .algorithm .study .test24 ;
22
3+ import org .junit .Test ;
4+
35/**
46 * 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。
57 * <p>
@@ -27,7 +29,6 @@ public ListNode swapPairs(ListNode head) {
2729 ListNode firstNode = head ;
2830 ListNode secondNode = head .next ;
2931
30-
3132 firstNode .next = secondNode .next ;
3233 secondNode .next = prev .next ;
3334 prev .next = secondNode ;
@@ -40,4 +41,22 @@ public ListNode swapPairs(ListNode head) {
4041 }
4142
4243
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+ }
4362}
Original file line number Diff line number Diff line change 33/**
44 * @author : chen weijie
55 * @Date: 2019-09-08 02:19
6+ * @Description: zhunn 删除排序链表中的重复元素
67 */
78public class Solution2 {
89
You can’t perform that action at this time.
0 commit comments