1290. 二进制链表转整数








class Solution(object):
    def getDecimalValue(self):
        """
        :type head: ListNode
        :rtype: int
        """
        list = []
        while head:
            list.append(head.val)
            head = head.next
        list = list[::-1]
        ans = 0
        for i in range(len(list)):
            ans += list[i] * (2 ** i)
        return ans
posted @ 2020-05-09 14:36  人间烟火地三鲜  阅读(122)  评论(0)    收藏  举报