File tree 3 files changed +70
-0
lines changed
solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,31 @@ class Solution {
120
120
}
121
121
```
122
122
123
+ ### ** JavaScript**
124
+
125
+ ``` js
126
+ /**
127
+ * Definition for singly-linked list.
128
+ * function ListNode(val) {
129
+ * this.val = val;
130
+ * this.next = null;
131
+ * }
132
+ */
133
+ /**
134
+ * @param {ListNode} head
135
+ * @return {number}
136
+ */
137
+ var getDecimalValue = function (head ) {
138
+ let res = 0 ;
139
+ while (head !== null ) {
140
+ res *= 2 ;
141
+ if (head .val ) res += 1 ;
142
+ head = head .next ;
143
+ }
144
+ return res;
145
+ };
146
+ ```
147
+
123
148
### ** ...**
124
149
125
150
```
Original file line number Diff line number Diff line change @@ -131,6 +131,31 @@ class Solution {
131
131
}
132
132
```
133
133
134
+ ### ** JavaScript**
135
+
136
+ ``` js
137
+ /**
138
+ * Definition for singly-linked list.
139
+ * function ListNode(val) {
140
+ * this.val = val;
141
+ * this.next = null;
142
+ * }
143
+ */
144
+ /**
145
+ * @param {ListNode} head
146
+ * @return {number}
147
+ */
148
+ var getDecimalValue = function (head ) {
149
+ let res = 0 ;
150
+ while (head !== null ) {
151
+ res *= 2 ;
152
+ if (head .val ) res += 1 ;
153
+ head = head .next ;
154
+ }
155
+ return res;
156
+ };
157
+ ```
158
+
134
159
### ** ...**
135
160
136
161
```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val) {
4
+ * this.val = val;
5
+ * this.next = null;
6
+ * }
7
+ */
8
+ /**
9
+ * @param {ListNode } head
10
+ * @return {number }
11
+ */
12
+ var getDecimalValue = function ( head ) {
13
+ let res = 0 ;
14
+ while ( head !== null ) {
15
+ res *= 2 ;
16
+ if ( head . val ) res += 1 ;
17
+ head = head . next ;
18
+ }
19
+ return res ;
20
+ } ;
You can’t perform that action at this time.
0 commit comments