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