LeetCode #1290 Convert Binary Number in a Linked List to Integer
var getDecimalValue = function(head) {
if(!head.next) return head.val;
let binary = "";
while(head.next) {
binary += head.val;
head = head.next;
if(!head.next) {
binary += head.val;
}
}
return parseInt(binary, 2);
};
// 다른 분의 풀이
let result = 0
while (head) {
result = result * 2 + head.val;
head = head.next
}
return result
};