import java.util.Stack;
/**
* Created by yanyongjun on 2020/2/14.
*/
class Solution {
public int getDecimalValue(ListNode head) {
if (head == null) {
return 0;
}
Stack<Integer> stack = new Stack<>();
stack.push(head.val);
while (head.next != null) {
head = head.next;
stack.push(head.val);
}
int result = 0;
int cur = 1;
while (!stack.isEmpty()) {
int tmp = stack.pop();
result = cur * tmp + result;
cur = cur * 2;
}
return result;
}
}