Convert Binary Number in a Linked List to Integer LeetCode solution in Rust

1
impl Solution {
2
pub fn get_decimal_value(head: Option<Box<ListNode>>) -> i32 {
3
let mut cur_node = &head;
4
let mut v = Vec::new();
5
while let Some(node) = cur_node {
6
v.push(node.val);
7
cur_node = &node.next;
8
}
9

10
v.iter()
11
.rev()
12
.enumerate()
13
.fold(0, |acc, (ind, val)| acc + *val * (1 << ind))
14
}
15
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0