class Solution:
def getDecimalValue(self, head: ListNode) -> int:
if not head:
return 0
temp=[]
while(head):
temp.append(head.val)
head=head.next
l=len(temp)
ans=0
for i in range(l):
ans+=(temp[~i]*(2**i))
return ans
leetcode---1290.二进制链表转整数
最新推荐文章于 2024-10-05 12:29:44 发布