[leetcode] 83. 刪除排序鏈表中的重復元素
阿新 • • 發佈:2018-07-30
ref null let 重復元素 ret http desc pub leet
83. 刪除排序鏈表中的重復元素
鏈表操作
class Solution { public ListNode deleteDuplicates(ListNode head) { if (head == null) return head; if (head.next == null) return head; ListNode now = head.next; ListNode last = head; while (now != null) { while (now != null && now.val == last.val) { now = now.next; } last.next = now; last = now; if (now != null) now = now.next; } return head; } }
[leetcode] 83. 刪除排序鏈表中的重復元素