Skip to content

Commit d2abe01

Browse files
authoredApr 27, 2021
Create 1290-convert-binary-number-in-a-linked-list-to-integer.js
1 parent 7238840 commit d2abe01

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val, next) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.next = (next===undefined ? null : next)
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @return {number}
11+
*/
12+
const getDecimalValue = function(head) {
13+
let res = 0
14+
15+
while(head) {
16+
res = res * 2 + head.val
17+
head = head.next
18+
}
19+
return res
20+
};

0 commit comments

Comments
 (0)
Please sign in to comment.