js版
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {number}
*/
var getDecimalValue = function (head) {
let p = head;
let arr = [];
while (p.next) {
arr.push(p.val)
p = p.next;
}
arr.push(p.val)
return parseInt(arr.join(""), 2)
};