#[derive(PartialEq, Eq, Debug)] pub struct ListNode { pub val: i32, pub next: Option>, } impl ListNode { #[inline] pub fn new(val: i32) -> Self { ListNode { next: None, val } } } // helper function for test 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()), *])}; }