Last active
September 19, 2019 16:29
-
-
Save lbvf50mobile/80e0c82d7cb9cbaa284fb127c4fcebd8 to your computer and use it in GitHub Desktop.
deleteDuplicates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode | |
# attr_accessor :val, :next | |
# def initialize(val) | |
# @val = val | |
# @next = nil | |
# end | |
# end | |
# @param {ListNode} head | |
# https://leetcode.com/problems/remove-duplicates-from-sorted-list/submissions/ | |
#Runtime: 40 ms, faster than 71.28% of Ruby online submissions for Remove Duplicates from Sorted List. | |
#Memory Usage: 9.3 MB, less than 100.00% of Ruby online submissions for Remove Duplicates from Sorted List. | |
# @return {ListNode} | |
def delete_duplicates(head) | |
pnt1, pnt2 = head, head | |
while pnt1 do | |
pnt2 = pnt1.next | |
while pnt2 && pnt1.val == pnt2.val do | |
pnt2 = pnt2.next | |
end | |
pnt1.next = pnt2 | |
pnt1 = pnt2 | |
end | |
head | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
https://leetcode.com/problems/remove-duplicates-from-sorted-list/submissions/ | |
Runtime: 4 ms, faster than 90.10% of Go online submissions for Remove Duplicates from Sorted List. | |
Memory Usage: 3.1 MB, less than 50.00% of Go online submissions for Remove Duplicates from Sorted List. | |
*/ | |
func deleteDuplicates(head *ListNode) *ListNode { | |
var pointer, pointer2 * ListNode | |
pointer = head | |
for ; pointer != nil ; { | |
pointer2 = pointer.Next | |
for ; pointer2 != nil && pointer2.Val == pointer.Val ; { | |
pointer2 = pointer2.Next | |
} | |
pointer.Next = pointer2 | |
pointer = pointer2 | |
} | |
return head | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* function ListNode(val) { | |
* this.val = val; | |
* this.next = null; | |
* } | |
*/ | |
/** | |
Runtime: 64 ms, faster than 79.29% of JavaScript online submissions for Remove Duplicates from Sorted List. | |
Memory Usage: 35.7 MB, less than 43.75% of JavaScript online submissions for Remove Duplicates from Sorted List. | |
https://leetcode.com/problems/remove-duplicates-from-sorted-list/submissions/ | |
*/ | |
var deleteDuplicates = function(head) { | |
let [pointer,pointer2] = [head,head] | |
for( ; pointer != null ;){ | |
for( pointer2 = pointer.next ; pointer2 != null && pointer2.val == pointer.val; ){ | |
pointer2 = pointer2.next | |
} | |
pointer.next = pointer2 | |
pointer = pointer2 | |
} | |
return head | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.next = None | |
# Runtime: 48 ms, faster than 69.45% of Python3 online submissions for Remove Duplicates from Sorted List. | |
# Memory Usage: 13.7 MB, less than 6.45% of Python3 online submissions for Remove Duplicates from Sorted List. | |
# https://leetcode.com/problems/remove-duplicates-from-sorted-list/submissions/ | |
class Solution: | |
def deleteDuplicates(self, head: ListNode) -> ListNode: | |
pnt1, pnt2 = head, head | |
while pnt1: | |
pnt2 = pnt1.next | |
while pnt2 and pnt1.val == pnt2.val: | |
pnt2 = pnt2.next | |
pnt1.next = pnt2 | |
pnt1 = pnt2 | |
return head | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://tour.golang.org/moretypes/4