Om's Brain

Home

❯

🔱 DSA

❯

Linked list

❯

3. Binery No. to LL

3. Binery No. to LL

Jun 30, 20261 min read

  • dsa
  • linked-list

https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/description/

class Solution {
public:
    int getDecimalValue(ListNode* head) {
        int ans = 0;
        while(head){
            ans = ans*2 + head->val;
            head = head->next; 
        }
        return ans;
    }
};


← Previous2. reverse-nodes-in-k-group

Mindmap

Graph View