Ive been trying to solve this problem it's able to surpass the first test case but it seems to be failing with the other edge cases , could somebody review the code and help me out , thanks.
class Solution:
def getDecimalValue(self, head: ListNode) -> int:
curr = head
z= 0
stk = []
#count = 0
while curr:
stk.append(curr.val)
curr = curr.next
for i,j in enumerate(stk):
z = j + 2**i
if stk[0] == 0 and stk[1:] == None:
return 0
elif stk[0] == 1 and stk[1:] == None:
return 1
else:
return z