- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1290.java
28 lines (25 loc) · 750 Bytes
/
_1290.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
packagecom.fishercoder.solutions.secondthousand;
importcom.fishercoder.common.classes.ListNode;
publicclass_1290 {
publicstaticclassSolution1 {
publicintgetDecimalValue(ListNodehead) {
StringBuildersb = newStringBuilder();
while (head != null) {
sb.append(head.val);
head = head.next;
}
returnInteger.parseInt(sb.toString(), 2);
}
}
publicstaticclassSolution2 {
publicintgetDecimalValue(ListNodehead) {
intsum = 0;
while (head != null) {
sum *= 2;
sum += head.val;
head = head.next;
}
returnsum;
}
}
}