diff --git a/README.md b/README.md deleted file mode 100644 index 7c3b229..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Algorithms 2019-2020 Python LEETCODE - -Check branches for information. \ No newline at end of file diff --git a/linked-list.md b/linked-list.md new file mode 100644 index 0000000..fed0b92 --- /dev/null +++ b/linked-list.md @@ -0,0 +1,34 @@ +# Linked list + ++ [Reorder List (deque)](#reorder-list-deque) + +## Reorder List (deque) + +https://leetcode.com/problems/reorder-list/ + +```python +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution(object): + def reorderList(self, head): + prev, curr = ListNode(0), head + q = collections.deque() + while head: + q.append(head) + head = head.next + + i = 1 + while q: + if i & 1: + curr = q.popleft() + else: + curr = q.pop() + prev.next = curr + prev = curr + i += 1 + if curr: curr.next = None + +``` \ No newline at end of file