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
        
posted @ 2019-12-24 14:35  oldby  阅读(185)  评论(0编辑  收藏  举报