File tree Expand file tree Collapse file tree 1 file changed +44
-1
lines changed Expand file tree Collapse file tree 1 file changed +44
-1
lines changed Original file line number Diff line number Diff line change 15
15
输出:1->1->2->3->4->4
16
16
```
17
17
18
- 今天的题目思路很简单,但是一遍AC也是不容易的。链表大部分题目考察的都是考生代码的完整性和鲁棒性,所以有些题目我们看着思路很简单,但是想直接通过还是需要下一翻工夫的,所以建议大家将所有链表的题目都自己写一下。实在没有时间做的同学,可以自己在脑子里打一遍代码,想清没一行代码的作用 。
18
+ 今天的题目思路很简单,但是一遍AC也是不容易的。链表大部分题目考察的都是考生代码的完整性和鲁棒性,所以有些题目我们看着思路很简单,但是想直接通过还是需要下一翻工夫的,所以建议大家将所有链表的题目都自己写一下。实在没有时间做的同学,可以自己在脑子里打一遍代码,想清每一行代码的作用 。
19
19
20
20
迭代法:
21
21
@@ -80,3 +80,46 @@ public:
80
80
};
81
81
```
82
82
83
+ JS Code:
84
+
85
+ ```js
86
+ var mergeTwoLists = function(l1, l2) {
87
+ let headpro = new ListNode(-1);
88
+ let headtemp = headpro;
89
+ while (l1 && l2) {
90
+ //接上大的那个
91
+ if (l1.val >= l2.val) {
92
+ headpro.next = l2;
93
+ l2 = l2.next;
94
+ }
95
+ else {
96
+ headpro.next = l1;
97
+ l1 = l1.next;
98
+ }
99
+ headpro = headpro.next;
100
+ }
101
+ headpro.next = l1 != null ? l1:l2;
102
+ return headtemp.next;
103
+ };
104
+ ```
105
+
106
+ Python Code:
107
+
108
+ ``` py
109
+ class Solution :
110
+ def mergeTwoLists (self , l1 : ListNode, l2 : ListNode) -> ListNode:
111
+ headpro = ListNode(- 1 )
112
+ headtemp = headpro
113
+ while l1 and l2:
114
+ # 接上大的那个
115
+ if l1.val >= l2.val:
116
+ headpro.next = l2
117
+ l2 = l2.next
118
+ else :
119
+ headpro.next = l1
120
+ l1 = l1.next
121
+ headpro = headpro.next
122
+ headpro.next = l1 if l1 is not None else l2
123
+ return headtemp.next
124
+ ```
125
+
You can’t perform that action at this time.
0 commit comments