leetcode 1290. Convert Binary Number in a Linked List to Integer

题目
好基础的题目,做的都不好意思了

class Solution {
     
    public int getDecimalValue(ListNode head) {
     
        int res = 0;
        while(head!=null){
     
            res = res*2+head.val;
            head = head.next;
        }
        return res;
    }
}

你可能感兴趣的:(leetcode)