We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db815cd commit f609dd7Copy full SHA for f609dd7
kotlin/0086-partition-list.kt
@@ -0,0 +1,25 @@
1
+class Solution {
2
+ fun partition(head: ListNode?, x: Int): ListNode? {
3
+ var leftPart = ListNode(0)
4
+ val rightPart = ListNode(0)
5
+
6
+ var cur = head
7
+ var left = leftPart
8
+ var right = rightPart
9
10
+ while (cur != null) {
11
+ if (cur.`val` < x) {
12
+ left?.next = cur
13
+ left = left?.next
14
+ } else {
15
+ right?.next = cur
16
+ right = right?.next
17
+ }
18
+ cur = cur?.next
19
20
21
+ right?.next = null
22
+ left?.next = rightPart?.next
23
+ return leftPart?.next
24
25
+}
0 commit comments