This is a super easy problem. Time Compexity O(n), Space Complexity O(n)
int res = 0; public int getDecimalValue(ListNode head) { if(head==null) return res; res = res*2+head.val; return getDecimalValue(head.next); }
int res = 0; public int getDecimalValue(ListNode head) { while(head!=null){ int val= head.val; res= res*2+val; head=head.next; } return res; }