initial commit
This commit is contained in:
commit
9bb6c0a361
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
/Cargo.lock
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "greedy-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
28
src/lib.rs
Normal file
28
src/lib.rs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let array: Vec<i32> = vec![1,2,3,6,4,5,7,8];
|
||||||
|
assert_eq!(find_outlier_and_sort(array), [1,2,3,4,5,6,7,8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_outlier_and_sort(array: Vec<i32>) -> Result<Vec<i32>,()> {
|
||||||
|
let mut i = 0;
|
||||||
|
let mut barnie = 0;
|
||||||
|
for num in array {
|
||||||
|
if i == 0{
|
||||||
|
if num > &array[i+1] {
|
||||||
|
barnie = num;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if &array[i-1] <= &array[i] <= &array[i+1]{
|
||||||
|
continue;
|
||||||
|
}else if &array[i-1] <= &array[i+1]{
|
||||||
|
barnie = num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue