Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.

Return the decimal value of the number in the linked list.

The most significant bit is at the head of the linked list.

&nbsp;
Example 1:

Input: head = [1,0,1]
Output: 5
Explanation: (101) in base 2 = (5) in base 10


Example 2:

Input: head = [0]
Output: 0


&nbsp;
Constraints:


	The Linked List is not empty.
	Number of nodes will not exceed 30.
	Each node's value is either 0 or 1.


# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def getDecimalValue(self, head: ListNode) -> int:
        res = 0
        po = 0
        stack = []
        node = head
        while node:
            stack.append(node.val)
            node = node.next
        res = 0
        for i in reversed(stack):
            res += i*(2**po)
            po += 1
        return res
/**
 * 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) {
        head = reverse(head);
        int ans = 0;
        int pow = 0;
        ListNode temp = head;
        while(temp != null){
            ans = ans + temp.val * (int) Math.pow(2,pow++);
            temp = temp.next;
        }

        return ans;
    }
    public ListNode reverse(ListNode head){
        ListNode prev = null;
        ListNode pres = head;
        ListNode Next = pres.next;

        while(pres != null){
            pres.next = prev;
            prev = pres;
            pres = Next;
            if(Next != null){
                Next = Next.next;
            }
        }

        head = prev;
        return head;
    }
}
class Solution {
public:
    int getDecimalValue(ListNode* head) {
        ListNode* temp = head;
        int count = 0;
        while(temp->next != NULL){
            count++;
            temp = temp->next;
        }
        temp = head;
        int ans = 0;
        while(count != -1){
            ans += temp->val * pow(2,count);
            count--;
            temp = temp->next;
        }
        return ans;
    }
};
var getDecimalValue = function(head) {
    let str = ""
    while(head){
        str += head.val
        head = head.next
    }
    return parseInt(str,2)    //To convert binary into Integer
Convert Binary Number in a Linked List to Integer