Skip to content

Commit

Permalink
Merge pull request neetcode-gh#3094 from emanuele-em/patch-5
Browse files Browse the repository at this point in the history
Update 0206-reverse-linked-list.rs
  • Loading branch information
a93a authored Oct 23, 2023
2 parents 4168e0f + e4a0dd0 commit e89cfed
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions rust/0206-reverse-linked-list.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
impl Solution {
pub fn reverse_list(mut head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
let mut node = None;
while let Some(next) = head {
node =
Some (
Box::new (
ListNode {
next : node,
val : next.val,
}
)
);
head = next.next;
}
node
let (mut prev, mut curr) = (None, head);
while let Some(mut node) = curr{
curr = node.next;
node.next = prev;
prev = Some(node);
}
pre
}
}

0 comments on commit e89cfed

Please sign in to comment.