LinkedList/convert_binary_linked_list_to_int library

🔢 Convert Binary Number in Linked List to Integer — MSB-first parsing

Parses a binary number represented as a singly linked list where the most significant bit appears first and returns its integer value. The implementation uses left-shift accumulation to avoid string conversion and minimize allocations.

Contract:

  • Inputs: head (nullable linked list of int values 0 or 1).
  • Output: integer value represented by the binary digits. Returns 0 for null.
  • Error modes: values other than 0/1 are not validated and may produce incorrect results.

Complexity: Time O(n), Space O(1).

Example:

final head = LinkedListNode.fromList([1,0,1]);
final value = convertBinaryLinkedListToInt(head);
// value: 5

Functions

convertBinaryLinkedListToInt(LinkedListNode<int>? head) → int