Skip to content
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

34 changes: 34 additions & 0 deletions linked-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Linked list

+ [Reorder List (deque)](#reorder-list-deque)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot from 2020-06-05 01-42-18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кого ты пытаешься удивить своим кодом? Ты написал простейшую задачу через какие-то сложности

Разбил список пополам, вторую половину развернул и слил в один список, все

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если нечёт, то делаем popleft, а если чёт, то просто pop. if i&1 та же проверка на нечётность, только короче. PEP8 щас поправлю.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не устраивает, решение сложное, надо упростить

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vivelapaix двусвязные списки так и просят использовать 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

```