Skip to content

Commit af11213

Browse files
authored
Create 0092-reverse-linked-list-ii.kt
1 parent d08a520 commit af11213

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

kotlin/0092-reverse-linked-list-ii.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
fun reverseBetween(head: ListNode?, left: Int, right: Int): ListNode? {
3+
val dummy: ListNode? = ListNode(0)
4+
dummy?.next = head
5+
6+
var cur = dummy
7+
repeat (left - 1) {
8+
cur = cur?.next
9+
}
10+
11+
var pre = cur
12+
var start = cur?.next
13+
var end = start?.next
14+
15+
repeat (right - left) {
16+
start?.next = end?.next
17+
end?.next = pre?.next
18+
pre?.next = end
19+
end = start?.next
20+
}
21+
22+
return dummy?.next
23+
}
24+
}

0 commit comments

Comments
 (0)