-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56f6ea6
commit 692bffc
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use log::warn; | ||
|
||
// Definition for singly-linked list. | ||
// #[derive(PartialEq, Eq, Clone, Debug)] | ||
pub struct ListNode { | ||
pub val: i32, | ||
pub next: Option<Box<ListNode>>, | ||
} | ||
|
||
impl ListNode { | ||
#[inline] | ||
fn new(val: i32) -> Self { | ||
ListNode { | ||
next: None, | ||
val, | ||
} | ||
} | ||
} | ||
|
||
pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> { | ||
let mut curr: Option<Box<ListNode>> = None; | ||
let mut next: Option<Box<ListNode>> = head; | ||
loop { | ||
if next.is_none() { | ||
break | ||
} | ||
let mut next_node: Box<ListNode> = next.take().unwrap(); | ||
let fwd = next_node.next.take(); | ||
next_node.next = curr.take(); | ||
curr = Some(next_node); | ||
next = fwd; | ||
} | ||
curr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod lc217; | |
pub mod lc242; | ||
pub mod lc74; | ||
pub mod lc143; | ||
pub mod lc206; |