File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed
src/main/kotlin/g0001_0100
s0021_merge_two_sorted_lists
s0023_merge_k_sorted_lists
s0024_swap_nodes_in_pairs Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -6,10 +6,19 @@ package g0001_0100.s0021_merge_two_sorted_lists
6
6
7
7
import com_github_leetcode.ListNode
8
8
9
+ /*
10
+ * Example:
11
+ * var li = ListNode(5)
12
+ * var v = li.`val`
13
+ * Definition for singly-linked list.
14
+ * class ListNode(var `val`: Int) {
15
+ * var next: ListNode? = null
16
+ * }
17
+ */
9
18
class Solution {
10
- fun mergeTwoLists (l1 : ListNode ? , l2 : ListNode ? ): ListNode ? {
11
- var l1 = l1
12
- var l2 = l2
19
+ fun mergeTwoLists (list1 : ListNode ? , list2 : ListNode ? ): ListNode ? {
20
+ var l1 = list1
21
+ var l2 = list2
13
22
var list: ListNode ? = ListNode (- 1 )
14
23
val head = list
15
24
while (l1 != null || l2 != null ) {
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import com_github_leetcode.ListNode
7
7
8
8
class Solution {
9
9
fun mergeKLists (lists : Array <ListNode >): ListNode ? {
10
- return if (lists.size == 0 ) {
10
+ return if (lists.isEmpty() ) {
11
11
null
12
12
} else mergeKLists(lists, 0 , lists.size)
13
13
}
@@ -23,9 +23,9 @@ class Solution {
23
23
}
24
24
}
25
25
26
- private fun mergeTwoLists (left : ListNode ? , right : ListNode ? ): ListNode ? {
27
- var left = left
28
- var right = right
26
+ private fun mergeTwoLists (leftLocal : ListNode ? , rightLocal : ListNode ? ): ListNode ? {
27
+ var left = leftLocal
28
+ var right = rightLocal
29
29
if (left == null ) {
30
30
return right
31
31
}
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ class Solution {
14
14
return reverse(head, len)
15
15
}
16
16
17
- private fun getLength (curr : ListNode ): Int {
18
- var curr: ListNode ? = curr
17
+ private fun getLength (currLocal : ListNode ): Int {
18
+ var curr: ListNode ? = currLocal
19
19
var cnt = 0
20
20
while (curr != null ) {
21
21
cnt++
You can’t perform that action at this time.
0 commit comments