diff --git a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md index 62b55c0068c08..7b897843715c2 100644 --- a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md +++ b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md @@ -163,6 +163,60 @@ func check(nums []int, i int) bool { } ``` +### **Rust** + +```rust +impl Solution { + pub fn can_be_increasing(nums: Vec) -> bool { + let check = |p: usize| -> bool { + let mut prev = None; + for j in 0..nums.len() { + if p != j { + if let Some(value) = prev { + if value >= nums[j] { + return false; + } + } + prev = Some(nums[j]); + } + } + true + }; + for i in 1..nums.len() { + if nums[i-1] >= nums[i] { + return check(i-1) || check(i) + } + } + true + } +} +``` + +### **TypeScript** + +```ts +function canBeIncreasing(nums: number[]): boolean { + const check = (p: number) => { + let prev = undefined; + for (let j = 0; j < nums.length; j++) { + if (p != j) { + if (prev !== undefined && prev >= nums[j]) { + return false; + } + prev = nums[j]; + } + } + return true; + }; + for (let i = 0; i < nums.length; i++) { + if (nums[i - 1] >= nums[i]) { + return check(i - 1) || check(i); + } + } + return true; +} +``` + ### **...** ``` diff --git a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md index 0a22c6c3c27e1..0d6f8544a076e 100644 --- a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md +++ b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md @@ -149,6 +149,60 @@ func check(nums []int, i int) bool { } ``` +### **Rust** + +```rust +impl Solution { + pub fn can_be_increasing(nums: Vec) -> bool { + let check = |p: usize| -> bool { + let mut prev = None; + for j in 0..nums.len() { + if p != j { + if let Some(value) = prev { + if value >= nums[j] { + return false; + } + } + prev = Some(nums[j]); + } + } + true + }; + for i in 1..nums.len() { + if nums[i-1] >= nums[i] { + return check(i-1) || check(i) + } + } + true + } +} +``` + +### **TypeScript** + +```ts +function canBeIncreasing(nums: number[]): boolean { + const check = (p: number) => { + let prev = undefined; + for (let j = 0; j < nums.length; j++) { + if (p != j) { + if (prev !== undefined && prev >= nums[j]) { + return false; + } + prev = nums[j]; + } + } + return true; + }; + for (let i = 0; i < nums.length; i++) { + if (nums[i - 1] >= nums[i]) { + return check(i - 1) || check(i); + } + } + return true; +} +``` + ### **...** ``` diff --git a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/Solution.rs b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/Solution.rs new file mode 100644 index 0000000000000..d7a4d69136a77 --- /dev/null +++ b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/Solution.rs @@ -0,0 +1,24 @@ +impl Solution { + pub fn can_be_increasing(nums: Vec) -> bool { + let check = |p: usize| -> bool { + let mut prev = None; + for j in 0..nums.len() { + if p != j { + if let Some(value) = prev { + if value >= nums[j] { + return false; + } + } + prev = Some(nums[j]); + } + } + true + }; + for i in 1..nums.len() { + if nums[i-1] >= nums[i] { + return check(i-1) || check(i) + } + } + true + } +} \ No newline at end of file diff --git a/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/Solution.ts b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/Solution.ts new file mode 100644 index 0000000000000..d81c5a9c7726b --- /dev/null +++ b/solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/Solution.ts @@ -0,0 +1,20 @@ +function canBeIncreasing(nums: number[]): boolean { + const check = (p: number) => { + let prev = undefined; + for (let j = 0; j < nums.length; j++) { + if (p != j) { + if (prev !== undefined && prev >= nums[j]) { + return false; + } + prev = nums[j]; + } + } + return true; + }; + for (let i = 0; i < nums.length; i++) { + if (nums[i - 1] >= nums[i]) { + return check(i - 1) || check(i); + } + } + return true; +}