Lintcode Python Simple class topic 35. Flip List

Source: Internet
Author: User

Title Description:

Flip a linked list

Have you ever encountered this problem in a real interview? Yes

Sample Example

Given a list of 1->2->3->null, this flipped list is 3->2->1->null

challenges

One-time rollover complete in situ

labelList of Facebook Uber steps

Topic Analysis:

One-time rollover complete in situ

Loop head linked list, the elements in the list from the table header in turn to the new linked list.

Source:

"" "Definition of Listnodeclass ListNode (object):    def __init__ (self, Val, next=none):        self.val = val        Self.next = Next "" "Class Solution:" "    @param head:the first node of the linked list.    @return: You should return the head of the reversed linked list.                   Reverse it in-place.    "" " def reverse (self, head):        # Write your code this        if head is None:return none        p = head        cur = none        Pre = None while P was not        None:            cur = p.next            p.next = pre            pre = p            p = cur        return pre

  

Lintcode Python Simple class topic 35. Flip List

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.