Created
January 14, 2020 12:36
-
-
Save rockonyu/8e8868f92e10bb9943b6ebb09e356dcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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