This is my CPP solution.
class Solution {
public:
int getDecimalValue(ListNode* head) {
vector<int> store;
ListNode* p = head;
while(p!=NULL){
store.push_back(p->val);
p = p->next;
}
int cnt = 0, n = store.size();
for(int i=0;i<store.size();i++){
cnt += (pow(2,n-1)*store[i]);
n--;
}
return cnt;
}
};