自己1:没什么好说的,就用最原始的方法就可以,也不难。
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def getDecimalValue(self, head):
"""
:type head: ListNode
:rtype: int
"""
if not head:
return None
er_num_list = list()
p = head
while p:
er_num_list.append(p.val)
p = p.next
er_num_list = er_num_list[::-1]
num = 0
count = 0
for i in er_num_list:
num += i*(2**count)
count +=1
return num