Convert Binary Number in a Linked List to Integer LeetCode solution in C++
1class Solution {2public:3int getDecimalValue(ListNode *head) {4ListNode *temp = head;5int count = 0;6while (temp->next != NULL) {7count++;8temp = temp->next;9}10temp = head;11int ans = 0;12while (count != -1) {13ans += temp->val * pow(2, count);14count--;15temp = temp->next;16}17return ans;18}19};