leetcode -. 206 inverted list

The first pull down sequence, another sequence is inserted into the list:

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        new_head=None
        while head:
            tmp=head.next
            head.next=new_head
            new_head=head
            head=tmp
        return new_head
When execution: 44 ms, beat the 93.17% of users in all python3 submission
Memory consumption: 14.9 MB, defeated 19.62% of users in all python3 submission
 
 
 
 
——2019.10.24
 
 

Guess you like

Origin www.cnblogs.com/taoyuxin/p/11734802.html
Recommended