leetcode-167周赛-1290-二进制链表转整数

题目描述:

 

 提交:

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def getDecimalValue(self, head: ListNode) -> int:
        if not head:
            return 0
        l = []
        cur = head
        while cur:
            l.append(str(cur.val))
            cur = cur.next
        res = "".join(l)
        res = int(res,2)
        return res
        

猜你喜欢

转载自www.cnblogs.com/oldby/p/12091368.html