1290.二进制链表转整数
/*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode(int val) { this.val = val; }* ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public int getDecimalValue(ListNode head) {Stack<Integer> stack = new Stack<>();while(head != null){stack.push(head.val);head = head.next;}int res = 0;int count = 0;while(!stack.empty()){int num = stack.pop();res += num * Math.pow(2,count);count++;}return res;}
}