Skip to content

1290-convert-binary-number-in-a-linked-list-to-integer

DevGod
DevGod
Elf Vtuber
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {number}
*/
var getDecimalValue = function(head) {
let ans = 0;
while(head){
ans = (ans<<1)|head.val;
head = head.next;
}
return ans;
};