Skip to content

206. Reverse Linked List_new.md#10

Open
X-XsleepZzz wants to merge 2 commits into
mainfrom
lilnoahhh-patch-8-1
Open

206. Reverse Linked List_new.md#10
X-XsleepZzz wants to merge 2 commits into
mainfrom
lilnoahhh-patch-8-1

Conversation

@X-XsleepZzz
Copy link
Copy Markdown
Owner

206. Reverse Linked List
Given the head of a singly linked list, reverse the list, and return the reversed list.
次は703. Kth Largest Element in a Stream

return reversed_head
```
これreversed_head=stack.pop()まではできていたので悔しい。
araiさんはこの問題をstackに分類していたので、これが想定解なのかな。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

current.next = None
return reversed_head
```
これreversed_head=stack.pop()まではできていたので悔しい。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

これ、stack の中で1つ目だけが特殊なのです。
なので、番兵を立てるか、分岐をするか、ループの外に出すかの選択になります。どれでもいいので発想できれば書けたでしょう。

あと、stack の中のノードがこの時点ではまだ .next で全部繋がっていることも意識しましょう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants