// Definition for singly-linked list. #[derive(PartialEq, Eq, Clone, Debug)] pub struct ListNode { pub val: i32, pub next: Option> } impl ListNode { #[inline] fn new(val: i32) -> Self { ListNode { next: None, val } } } pub fn to_list(vec: Vec) -> Option> { let mut current = None; for &v in vec.iter().rev() { let mut node = ListNode::new(v); node.next = current; current = Some(Box::new(node)); } current } #[macro_export] macro_rules! linked { ($($e:expr),*) => {to_list(vec![$($e.to_owned()), *])}; ($($e:expr,)*) => {to_list(vec![$($e.to_owned()), *])}; }