-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Meng Wei
authored and
Meng Wei
committed
Jan 12, 2018
1 parent
714a4cb
commit ebe67dd
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Definition for singly-linked list. | ||
# class ListNode(object): | ||
# def __init__(self, x): | ||
# self.val = x | ||
# self.next = None | ||
|
||
class Solution(object): | ||
def swapPairs(self, head): | ||
""" | ||
:type head: ListNode | ||
:rtype: ListNode | ||
""" | ||
dummy = ListNode(0) | ||
dummy.next = head | ||
ret = dummy | ||
while dummy.next and dummy.next.next: | ||
curr = dummy.next | ||
after = curr.next | ||
temp = after.next | ||
dummy.next = after | ||
after.next = curr | ||
curr.next = temp | ||
|
||
dummy = dummy.next.next | ||
return ret.next |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Definition for singly-linked list. | ||
# class ListNode(object): | ||
# def __init__(self, x): | ||
# self.val = x | ||
# self.next = None | ||
|
||
class Solution(object): | ||
def deleteDuplicates(self, head): | ||
""" | ||
:type head: ListNode | ||
:rtype: ListNode | ||
""" | ||
ret = head | ||
while head and head.next: | ||
if head.next.val == head.val: | ||
head.next = head.next.next | ||
else: | ||
head = head.next | ||
return ret |