forked from DmrfCoder/AlgorithmAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14.py
42 lines (32 loc) · 765 Bytes
/
14.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding:utf-8 -*-
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# 返回ListNode
def ReverseList(self, pHead):
# write code here
if pHead == None:
return None
newHead=ListNode(pHead.val)
newHead.next=None
pHead=pHead.next
while pHead!=None:
cHead=ListNode(pHead.val)
cHead.next=newHead
newHead=cHead
pHead=pHead.next
return newHead
head = ListNode(1)
node1 = ListNode(2)
node2 = ListNode(3)
node3 = ListNode(4)
node4 = ListNode(5)
head.next = node1
node1.next = node2
node2.next = node3
node3.next = node4
solution = Solution()
newHead=solution.ReverseList(head)
a=1