1290. Convert Binary Number in a Linked List to Integer Easy
1/**
2 * [1290] Convert Binary Number in a Linked List to Integer
3 *
4 * Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.
5 * Return the decimal value of the number in the linked list.
6 * The most significant bit is at the head of the linked list.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2019/12/05/graph-1.png" style="width: 426px; height: 108px;" />
10 * Input: head = [1,0,1]
11 * Output: 5
12 * Explanation: (101) in base 2 = (5) in base 10
13 *
14 * Example 2:
15 *
16 * Input: head = [0]
17 * Output: 0
18 *
19 *
20 * Constraints:
21 *
22 * The Linked List is not empty.
23 * Number of nodes will not exceed 30.
24 * Each node's value is either 0 or 1.
25 *
26 */
27pub struct Solution {}
28use crate::util::linked_list::{ListNode, to_list};
29
30// problem: https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/
31// discuss: https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35// Definition for singly-linked list.
36// #[derive(PartialEq, Eq, Clone, Debug)]
37// pub struct ListNode {
38// pub val: i32,
39// pub next: Option<Box<ListNode>>
40// }
41//
42// impl ListNode {
43// #[inline]
44// fn new(val: i32) -> Self {
45// ListNode {
46// next: None,
47// val
48// }
49// }
50// }
51impl Solution {
52 pub fn get_decimal_value(head: Option<Box<ListNode>>) -> i32 {
53 0
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_1290() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.