deno.land / x / masx200_leetcode_test@10.6.5 / convert-binary-number-in-a-linked-list-to-integer / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
import { 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;}
masx200_leetcode_test

Version Info

Tagged at
a year ago