【leetcode】1290. 二进制链表转整数

 

int getDecimalValue(struct ListNode* head){
    int ans=0;
    struct ListNode* cur=head;
    while(cur){
        ans=ans*2+cur->val;
        cur=cur->next;
    }
    return ans;
}

 

posted @ 2020-11-25 18:18  温暖了寂寞  阅读(64)  评论(0编辑  收藏  举报