原题链接
解题思路,二进制转十进制模拟法
/*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode(int x) : val(x), next(NULL) {}* };*/
class Solution {
public:int getDecimalValue(ListNode* head) {ListNode* cur = head;int ans = 0;while (cur != nullptr) {ans = ans * 2 + cur->val;cur = cur->next;}return ans;}
};