|
2 | 2 |
|
3 | 3 | importcom.fishercoder.common.classes.ListNode;
|
4 | 4 |
|
5 |
| -/** |
6 |
| - * 1290. Convert Binary Number in a Linked List to Integer |
7 |
| - * |
8 |
| - * Given head which is a reference node to a singly-linked list. |
9 |
| - * The value of each node in the linked list is either 0 or 1. |
10 |
| - * The linked list holds the binary representation of a number. |
11 |
| - * |
12 |
| - * Return the decimal value of the number in the linked list. |
13 |
| - * |
14 |
| - * Example 1: |
15 |
| - * Input: head = [1,0,1] |
16 |
| - * Output: 5 |
17 |
| - * Explanation: (101) in base 2 = (5) in base 10 |
18 |
| - * |
19 |
| - * Example 2: |
20 |
| - * Input: head = [0] |
21 |
| - * Output: 0 |
22 |
| - * |
23 |
| - * Example 3: |
24 |
| - * Input: head = [1] |
25 |
| - * Output: 1 |
26 |
| - * |
27 |
| - * Example 4: |
28 |
| - * Input: head = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0] |
29 |
| - * Output: 18880 |
30 |
| - * |
31 |
| - * Example 5: |
32 |
| - * Input: head = [0,0] |
33 |
| - * Output: 0 |
34 |
| - * |
35 |
| - * Constraints: |
36 |
| - * |
37 |
| - * The Linked List is not empty. |
38 |
| - * Number of nodes will not exceed 30. |
39 |
| - * Each node's value is either 0 or 1. |
40 |
| - * */ |
41 | 5 | publicclass_1290 {
|
42 | 6 | publicstaticclassSolution1 {
|
43 | 7 | publicintgetDecimalValue(ListNodehead) {
|
|