题目

/**
 * 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 ans=0;
        while(head!=NULL)
        {
            ans = (ans<<1)|(head->val);
            head=head->next;
        }
        return ans;
        
    }
};

相关文章:

  • 2022-01-06
  • 2021-06-18
  • 2021-12-17
  • 2021-11-04
  • 2021-05-27
  • 2021-06-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-07-14
相关资源
相似解决方案