Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6b3eaa6

Browse files
committed
Update linked_list.md
1 parent 9220f91 commit 6b3eaa6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎data_structure/linked_list.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ ListNode* deleteDuplicates(ListNode* head) {
160160
161161
思路:用一个 prev 节点保存向前指针,node 保存向后的临时指针
162162
163+
**Python版本**
164+
```python
165+
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
166+
if head is None: return head
167+
168+
prev = None
169+
cur = head
170+
while cur != None:
171+
node = cur.next
172+
cur.next = prev
173+
prev = cur
174+
cur = node
175+
return prev
176+
```
177+
178+
179+
**C++版本**
163180
```cpp
164181
ListNode* reverseList(ListNode* head) {
165182
if(head == nullptr) return head;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /