234. Palindrome Linked List Easy

@problem@discussion
#Linked List#Two Pointers#Stack#Recursion



1/**
2 * [234] Palindrome Linked List
3 *
4 * Given the head of a singly linked list, return true if it is a palindrome or false otherwise.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg" style="width: 422px; height: 62px;" />
8 * Input: head = [1,2,2,1]
9 * Output: true
10 * 
11 * Example 2:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/03/pal2linked-list.jpg" style="width: 182px; height: 62px;" />
13 * Input: head = [1,2]
14 * Output: false
15 * 
16 *  
17 * Constraints:
18 * 
19 * 	The number of nodes in the list is in the range [1, 10^5].
20 * 	0 <= Node.val <= 9
21 * 
22 *  
23 * Follow up: Could you do it in O(n) time and O(1) space?
24 */
25pub struct Solution {}
26use crate::util::linked_list::{ListNode, to_list};
27
28// problem: https://leetcode.com/problems/palindrome-linked-list/
29// discuss: https://leetcode.com/problems/palindrome-linked-list/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33// Definition for singly-linked list.
34// #[derive(PartialEq, Eq, Clone, Debug)]
35// pub struct ListNode {
36//   pub val: i32,
37//   pub next: Option<Box<ListNode>>
38// }
39// 
40// impl ListNode {
41//   #[inline]
42//   fn new(val: i32) -> Self {
43//     ListNode {
44//       next: None,
45//       val
46//     }
47//   }
48// }
49impl Solution {
50    pub fn is_palindrome(head: Option<Box<ListNode>>) -> bool {
51        false
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_234() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.