Skip to content

Commit f1fe7f4

Browse files
committed
Create 0083-remove-duplicates-from-sorted-list.kt
1 parent ab692d6 commit f1fe7f4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)