/**
* 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) {
int sum=0;
while(head!=nullptr){
sum=sum*2+head->val;
head=head->next;
}
return sum;
}
};
2_二进制链表转整数
最新推荐文章于 2024-03-11 16:21:53 发布