deno.land / x / masx200_leetcode_test@10.6.5 / convert-binary-number-in-a-linked-list-to-integer / index.ts
12345678910111213import { ListNode } from "../reverse-linked-list/ListNode.ts";
export default function getDecimalValue(head: ListNode | null): number { if (head?.val === 0) return getDecimalValue(head.next); if (!head) return 0; let ans = 0; while (head) { ans = ans * 2 + head.val; head = head.next; } return ans;}
Version Info