MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / partition

Method partition

86. Partition List/src/main.rs:41–59  ·  view source on GitHub ↗
(mut head: Option<Box<ListNode>>, x: i32)

Source from the content-addressed store, hash-verified

39
40impl Solution {
41 pub fn partition(mut head: Option<Box<ListNode>>, x: i32) -> Option<Box<ListNode>> {
42 let mut h1 = ListNode::new(0);
43 let mut h2 = ListNode::new(0);
44 let mut p1 = &mut h1;
45 let mut p2 = &mut h2;
46 while head.is_some() {
47 let mut node = head.unwrap();
48 head = node.next.take();
49 if node.val < x {
50 p1.next = Some(node);
51 p1 = p1.next.as_mut().unwrap();
52 } else {
53 p2.next = Some(node);
54 p2 = p2.next.as_mut().unwrap();
55 }
56 }
57 p1.next = h2.next;
58 h1.next
59 }
60}
61
62#[cfg(test)]

Callers 1

longest_substring_reMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected