Skip to content

Commit 3514064

Browse files
authored
feat: add javascript solution to lc problem: No.1290.Convert Binary Number in a Linked List to Integer (doocs#413)
1 parent fe6e594 commit 3514064

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ class Solution {
120120
}
121121
```
122122

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+
123148
### **...**
124149

125150
```

solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md

+25
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,31 @@ class Solution {
131131
}
132132
```
133133

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+
134159
### **...**
135160

136161
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
};

0 commit comments

Comments
 (0)