Skip to content

Instantly share code, notes, and snippets.

@rockonyu
Created January 14, 2020 12:36
Show Gist options
  • Save rockonyu/8e8868f92e10bb9943b6ebb09e356dcd to your computer and use it in GitHub Desktop.
Save rockonyu/8e8868f92e10bb9943b6ebb09e356dcd to your computer and use it in GitHub Desktop.
var getDecimalValue = function(head) {
const items = [];
let currentHead = head;
while(currentHead !== null) {
items.push(currentHead.val);
currentHead = currentHead.next;
}
let sum = 0;
let position = 0;
while (items.length > 0) {
sum += items.pop() === 0 ? 0 : (1 << position);
position++;
}
return sum;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment