File tree 3 files changed +62
-1
lines changed
3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 45
45
| [ 067] [ 067-question ] | [ Add Binary] [ 067-tips ] | [ ✅] [ 067-java ] | | [ ✅] [ 067-kotlin ] |
46
46
| [ 069] [ 069-question ] | [ Sqrt(x)] [ 069-tips ] | [ ✅] [ 069-java ] | | [ ✅] [ 069-kotlin ] |
47
47
| [ 070] [ 070-question ] | [ Climbing Stairs] [ 070-tips ] | [ ✅] [ 070-java ] | | [ ✅] [ 070-kotlin ] |
48
- | [ 083] [ 083-question ] | [ Remove Duplicates from Sorted List] [ 083-tips ] | [ ✅] [ 083-java ] | | |
48
+ | [ 083] [ 083-question ] | [ Remove Duplicates from Sorted List] [ 083-tips ] | [ ✅] [ 083-java ] | | [ ✅ ] [ 083-kotlin ] |
49
49
| [ 088] [ 088-question ] | [ Merge Sorted Array] [ 088-tips ] | [ ✅] [ 088-java ] | | |
50
50
| [ 100] [ 100-question ] | [ Same Tree] [ 100-tips ] | [ ✅] [ 100-java ] | | |
51
51
| [ 101] [ 101-question ] | [ Symmetric Tree] [ 101-tips ] | [ ✅] [ 101-java ] | | |
489
489
[ 067-kotlin ] : ./src/_067/kotlin/Solution.kt
490
490
[ 069-kotlin ] : ./src/_069/kotlin/Solution.kt
491
491
[ 070-kotlin ] : ./src/_070/kotlin/Solution.kt
492
+ [ 083-kotlin ] : ./src/_083/kotlin/Solution.kt
492
493
[ 771-kotlin ] : ./src/_771/kotlin/Solution.kt
Original file line number Diff line number Diff line change
1
+ package _083.kotlin
2
+
3
+ import structure.ListNode
4
+
5
+ /* *
6
+ * @author relish
7
+ * @since 2018/04/23
8
+ */
9
+ /* *
10
+ * Definition for singly-linked list.
11
+ * class ListNode(var `val`: Int = 0) {
12
+ * var next: ListNode? = null
13
+ * }
14
+ */
15
+ class Solution {
16
+ fun deleteDuplicates (head : ListNode ? ): ListNode ? {
17
+ if (head == null ) return head
18
+ var cur = head
19
+ while (cur!! .next != null ) {
20
+ if (cur.`val ` == cur.next.`val `) {
21
+ cur.next = cur.next.next
22
+ } else {
23
+ cur = cur.next
24
+ }
25
+ }
26
+ return head
27
+ }
28
+ }
29
+
30
+ fun main (args : Array <String >) {
31
+ val n = ListNode (1 )
32
+ n.next = ListNode (1 )
33
+ n.next.next = ListNode (2 )
34
+ n.next.next.next = ListNode (3 )
35
+ n.next.next.next.next = ListNode (3 )
36
+ var listNode = Solution ().deleteDuplicates(n)
37
+ while (listNode != null ) {
38
+ println (listNode.`val `)
39
+ listNode = listNode.next
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ Given `1->1->2->3->3`, return `1->2->3`.
17
17
18
18
题意是删除链表中重复的元素,很简单,我们只需要遍历一遍链表,遇到链表中相邻元素相同时,把当前指针指向下下个元素即可。
19
19
20
+ Java:
20
21
``` java
21
22
/**
22
23
* Definition for singly-linked list.
@@ -42,6 +43,24 @@ class Solution {
42
43
}
43
44
```
44
45
46
+ kotlin(224ms/100.00%)
47
+ ``` kotlin
48
+ class Solution {
49
+ fun deleteDuplicates (head : ListNode ? ): ListNode ? {
50
+ if (head == null ) return head
51
+ var cur = head
52
+ while (cur!! .next != null ) {
53
+ if (cur.`val ` == cur.next.`val `) {
54
+ cur.next = cur.next.next
55
+ } else {
56
+ cur = cur.next
57
+ }
58
+ }
59
+ return head
60
+ }
61
+ }
62
+ ```
63
+
45
64
46
65
## 结语
47
66
You can’t perform that action at this time.
0 commit comments