Created
December 3, 2020 21:20
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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