File tree 1 file changed +10
-9
lines changed
scripts/algorithms/C/Convert Binary Number in a Linked List to Integer
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 0 ms (Top 100.00%) | Memory: 41.4 MB (Top 64.79%)
1
2
/**
2
3
* Definition for singly-linked list.
3
4
* public class ListNode {
4
- * int val;
5
- * ListNode next;
6
- * ListNode() {}
7
- * ListNode(int val) { this.val = val; }
8
- * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
5
+ * int val;
6
+ * ListNode next;
7
+ * ListNode() {}
8
+ * ListNode(int val) { this.val = val; }
9
+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9
10
* }
10
11
*/
11
12
class Solution {
@@ -18,14 +19,14 @@ public int getDecimalValue(ListNode head) {
18
19
ans = ans + temp .val * (int ) Math .pow (2 ,pow ++);
19
20
temp = temp .next ;
20
21
}
21
-
22
+
22
23
return ans ;
23
24
}
24
25
public ListNode reverse (ListNode head ){
25
26
ListNode prev = null ;
26
27
ListNode pres = head ;
27
28
ListNode Next = pres .next ;
28
-
29
+
29
30
while (pres != null ){
30
31
pres .next = prev ;
31
32
prev = pres ;
@@ -34,8 +35,8 @@ public ListNode reverse(ListNode head){
34
35
Next = Next .next ;
35
36
}
36
37
}
37
-
38
+
38
39
head = prev ;
39
40
return head ;
40
41
}
41
- }
42
+ }
You can’t perform that action at this time.
0 commit comments