https://leetcode.com/problems/palindrome-linked-list/
C 言語を勉強していたときに連結リストの存在は知っていたので、なんとなく連結リストの中身のとり方はイメージできていた。 reverse()メソッドは返り値がほしいなと思った。
impl Solution {
pub fn is_palindrome(head: Option<Box<ListNode>>) -> bool {
let mut current: Option<Box<ListNode>> = head;
let mut vec: Vec<i32> = Vec::new();
while let Some(list) = current {
current = list.next;
vec.push(list.val);
}
let len = vec.len() / 2;
let mut vec2 = vec.split_off(len);
vec2.reverse();
vec == vec2[..len]
}
}