Skip to content

Instantly share code, notes, and snippets.

@kingsamadesu
Created December 3, 2020 21:20
Show Gist options
  • Save kingsamadesu/adf68314e452ed277267400b067857a6 to your computer and use it in GitHub Desktop.
Save kingsamadesu/adf68314e452ed277267400b067857a6 to your computer and use it in GitHub Desktop.
1290. Convert Binary Number in a Linked List to Integer -with java- (leetcode.com)
/*
Your runtime beats 100.00 % of java submissions.
Your memory usage beats 83.62 % of java submissions.
*/
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public int getDecimalValue(ListNode head) {
int sum=0;
do{
sum = sum*2 + head.val;
head = head.next;
}while(head!=null);
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment