Convert Binary Number in a Linked List to Integer LeetCode solution in Python
1# Definition for singly-linked list.2# class ListNode:3# def __init__(self, val=0, next=None):4# self.val = val5# self.next = next6class Solution:7def getDecimalValue(self, head: ListNode) -> int:8res = 09po = 010stack = []11node = head12while node:13stack.append(node.val)14node = node.next15res = 016for i in reversed(stack):17res += i * (2**po)18po += 119return res