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 8f4638b commit ab692d6Copy full SHA for ab692d6
kotlin/0203-remove-linked-list-elements.kt
@@ -0,0 +1,27 @@
1
+/**
2
+ * Example:
3
+ * var li = ListNode(5)
4
+ * var v = li.`val`
5
+ * Definition for singly-linked list.
6
+ * class ListNode(var `val`: Int) {
7
+ * var next: ListNode? = null
8
+ * }
9
+ */
10
+class Solution {
11
+ fun removeElements(head: ListNode?, `val`: Int): ListNode? {
12
+
13
+ var dummy = ListNode(0, head)
14
+ var current = head
15
+ var prev = dummy
16
17
+ while(current != null) {
18
+ if(current?.`val` == `val`)
19
+ prev.next = current.next
20
+ else
21
+ prev = current
22
+ current = current.next
23
+ }
24
25
+ return dummy.next
26
27
+}
0 commit comments