Convert Binary Number in a Linked List to Integer 2020-10-24 08:44
public static int getDecimalValue(ListNode head) {
if (head == null) {
return 0;
}
int res = 0;
while (head != null) {
res = res * 2 + head.val;
head = head.next;
}
return res;
}
| Runtime | Memory |
|---|---|
| 0 ms | 36.3 MB |
EOF