-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.rs
64 lines (58 loc) · 1.92 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
fn main() {
let n = ListNode::new(5);
let n = ListNode { val: 4, next: Some(Box::new(n)) };
let n = ListNode { val: 4, next: Some(Box::new(n)) };
let n = ListNode { val: 3, next: Some(Box::new(n)) };
let n = ListNode { val: 3, next: Some(Box::new(n)) };
let n = ListNode { val: 2, next: Some(Box::new(n)) };
let n = ListNode { val: 1, next: Some(Box::new(n)) };
let head1 = Some(Box::new(n));
let n = ListNode::new(5);
let n = ListNode { val: 2, next: Some(Box::new(n)) };
let n = ListNode { val: 1, next: Some(Box::new(n)) };
let head2 = Some(Box::new(n));
assert_eq!(Solution::delete_duplicates(head1), head2);
}
struct Solution {}
// 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
}
}
}
impl Solution {
/// [not implemented] use c++
pub fn delete_duplicates(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
let newhead = None;
newhead
}
}
#[cfg(test)]
mod test {
use crate::*;
#[test]
fn basic() {
let n = ListNode::new(5);
let n = ListNode { val: 4, next: Some(Box::new(n)) };
let n = ListNode { val: 4, next: Some(Box::new(n)) };
let n = ListNode { val: 3, next: Some(Box::new(n)) };
let n = ListNode { val: 3, next: Some(Box::new(n)) };
let n = ListNode { val: 2, next: Some(Box::new(n)) };
let n = ListNode { val: 1, next: Some(Box::new(n)) };
let head1 = Some(Box::new(n));
let n = ListNode::new(5);
let n = ListNode { val: 2, next: Some(Box::new(n)) };
let n = ListNode { val: 1, next: Some(Box::new(n)) };
let head2 = Some(Box::new(n));
assert_eq!(Solution::delete_duplicates(head1), head2);
}
}