File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1290. Convert Binary Number in a Linked List to Integer
3
+ * https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given `head` which is a reference node to a singly-linked list.
7
+ * The value of each node in the linked list is either 0 or 1.
8
+ * The linked list holds the binary representation of a number.
9
+ * Return the decimal value of the number in the linked list.
10
+ */
11
+
12
+ /**
13
+ * Definition for singly-linked list.
14
+ * function ListNode(val) {
15
+ * this.val = val;
16
+ * this.next = null;
17
+ * }
18
+ */
19
+ /**
20
+ * @param {ListNode } head
21
+ * @return {number }
22
+ */
23
+ var getDecimalValue = function ( head ) {
24
+ let binary = String ( head . val ) ;
25
+
26
+ while ( head . next !== null ) {
27
+ head = head . next ;
28
+ binary += head . val ;
29
+ }
30
+
31
+ return parseInt ( binary , 2 ) ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments