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 ab692d6 commit f1fe7f4Copy full SHA for f1fe7f4
kotlin/0083-remove-duplicates-from-sorted-list.kt
@@ -0,0 +1,26 @@
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 deleteDuplicates(head: ListNode?): ListNode? {
12
+ var dummy = ListNode(Integer.MAX_VALUE, head)
13
+ var prev = dummy
14
+ var current = head
15
+
16
+ while(current != null) {
17
+ if(current.`val` == prev.`val`)
18
+ prev.next = current.next
19
+ else
20
+ prev = current
21
+ current = current.next
22
+ }
23
24
+ return dummy.next
25
26
+}
0 commit comments