diff options
author | Orangerot <purple@orangerot.dev> | 2024-06-27 11:30:16 +0200 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-06-27 11:30:16 +0200 |
commit | 4b0a6a01b051a4ebfbc17661d14cb23fe4f275fb (patch) | |
tree | 0072cca328fe5adb2ed61004010228ff85e2164d /remove-one-element-to-make-the-array-strictly-increasing |
Diffstat (limited to 'remove-one-element-to-make-the-array-strictly-increasing')
-rw-r--r-- | remove-one-element-to-make-the-array-strictly-increasing/Cargo.toml | 8 | ||||
-rw-r--r-- | remove-one-element-to-make-the-array-strictly-increasing/src/main.rs | 20 |
2 files changed, 28 insertions, 0 deletions
diff --git a/remove-one-element-to-make-the-array-strictly-increasing/Cargo.toml b/remove-one-element-to-make-the-array-strictly-increasing/Cargo.toml new file mode 100644 index 0000000..ccf1b7c --- /dev/null +++ b/remove-one-element-to-make-the-array-strictly-increasing/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "remove-one-element-to-make-the-array-strictly-increasing" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/remove-one-element-to-make-the-array-strictly-increasing/src/main.rs b/remove-one-element-to-make-the-array-strictly-increasing/src/main.rs new file mode 100644 index 0000000..d9f5304 --- /dev/null +++ b/remove-one-element-to-make-the-array-strictly-increasing/src/main.rs @@ -0,0 +1,20 @@ +fn main() { + println!("Hello, world!"); + let tests = [ + (vec![1,2,10,5,7], true), + (vec![2,3,1,2], false), + (vec![1,1,1], false) + ]; + for test in tests { + println!("{:?} is {} should be {}", test.0, Solution::can_be_increasing(test.0.clone()), + test.1); + } +} + +struct Solution; + +impl Solution { + pub fn can_be_increasing(nums: Vec<i32>) -> bool { + nums.windows(2).filter(|x| x[0] < x[1]).count() + 2 == nums.len() + } +} |