143. Reorder List Medium

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



1/**
2 * [143] Reorder List
3 *
4 * You are given the head of a singly linked-list. The list can be represented as:
5 * 
6 * L0 → L1 → … → Ln - 1 → Ln
7 * 
8 * Reorder the list to be on the following form:
9 * 
10 * L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …
11 * 
12 * You may not modify the values in the list's nodes. Only nodes themselves may be changed.
13 *  
14 * Example 1:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/04/reorder1linked-list.jpg" style="width: 422px; height: 222px;" />
16 * Input: head = [1,2,3,4]
17 * Output: [1,4,2,3]
18 * 
19 * Example 2:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/09/reorder2-linked-list.jpg" style="width: 542px; height: 222px;" />
21 * Input: head = [1,2,3,4,5]
22 * Output: [1,5,2,4,3]
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	The number of nodes in the list is in the range [1, 5 * 10^4].
28 * 	1 <= Node.val <= 1000
29 * 
30 */
31pub struct Solution {}
32use crate::util::linked_list::{ListNode, to_list};
33
34// problem: https://leetcode.com/problems/reorder-list/
35// discuss: https://leetcode.com/problems/reorder-list/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39// Definition for singly-linked list.
40// #[derive(PartialEq, Eq, Clone, Debug)]
41// pub struct ListNode {
42//   pub val: i32,
43//   pub next: Option<Box<ListNode>>
44// }
45// 
46// impl ListNode {
47//   #[inline]
48//   fn new(val: i32) -> Self {
49//     ListNode {
50//       next: None,
51//       val
52//     }
53//   }
54// }
55impl Solution {
56    pub fn reorder_list(head: &mut Option<Box<ListNode>>) {
57        
58    }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65    use super::*;
66
67    #[test]
68    fn test_143() {
69    }
70}
71


Back
© 2025 bowen.ge All Rights Reserved.