Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 44de958

Browse files
authored
feat: add rust and typescript solutions to lc problem: No.1909 (doocs#1842)
No.1909.Remove One Element to Make the Array Strictly Increasing
1 parent 67d7652 commit 44de958

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,60 @@ func check(nums []int, i int) bool {
163163
}
164164
```
165165

166+
### **Rust**
167+
168+
```rust
169+
impl Solution {
170+
pub fn can_be_increasing(nums: Vec<i32>) -> bool {
171+
let check = |p: usize| -> bool {
172+
let mut prev = None;
173+
for j in 0..nums.len() {
174+
if p != j {
175+
if let Some(value) = prev {
176+
if value >= nums[j] {
177+
return false;
178+
}
179+
}
180+
prev = Some(nums[j]);
181+
}
182+
}
183+
true
184+
};
185+
for i in 1..nums.len() {
186+
if nums[i-1] >= nums[i] {
187+
return check(i-1) || check(i)
188+
}
189+
}
190+
true
191+
}
192+
}
193+
```
194+
195+
### **TypeScript**
196+
197+
```ts
198+
function canBeIncreasing(nums: number[]): boolean {
199+
const check = (p: number) => {
200+
let prev = undefined;
201+
for (let j = 0; j < nums.length; j++) {
202+
if (p != j) {
203+
if (prev !== undefined && prev >= nums[j]) {
204+
return false;
205+
}
206+
prev = nums[j];
207+
}
208+
}
209+
return true;
210+
};
211+
for (let i = 0; i < nums.length; i++) {
212+
if (nums[i - 1] >= nums[i]) {
213+
return check(i - 1) || check(i);
214+
}
215+
}
216+
return true;
217+
}
218+
```
219+
166220
### **...**
167221

168222
```

solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing/README_EN.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,60 @@ func check(nums []int, i int) bool {
149149
}
150150
```
151151

152+
### **Rust**
153+
154+
```rust
155+
impl Solution {
156+
pub fn can_be_increasing(nums: Vec<i32>) -> bool {
157+
let check = |p: usize| -> bool {
158+
let mut prev = None;
159+
for j in 0..nums.len() {
160+
if p != j {
161+
if let Some(value) = prev {
162+
if value >= nums[j] {
163+
return false;
164+
}
165+
}
166+
prev = Some(nums[j]);
167+
}
168+
}
169+
true
170+
};
171+
for i in 1..nums.len() {
172+
if nums[i-1] >= nums[i] {
173+
return check(i-1) || check(i)
174+
}
175+
}
176+
true
177+
}
178+
}
179+
```
180+
181+
### **TypeScript**
182+
183+
```ts
184+
function canBeIncreasing(nums: number[]): boolean {
185+
const check = (p: number) => {
186+
let prev = undefined;
187+
for (let j = 0; j < nums.length; j++) {
188+
if (p != j) {
189+
if (prev !== undefined && prev >= nums[j]) {
190+
return false;
191+
}
192+
prev = nums[j];
193+
}
194+
}
195+
return true;
196+
};
197+
for (let i = 0; i < nums.length; i++) {
198+
if (nums[i - 1] >= nums[i]) {
199+
return check(i - 1) || check(i);
200+
}
201+
}
202+
return true;
203+
}
204+
```
205+
152206
### **...**
153207

154208
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
impl Solution {
2+
pub fn can_be_increasing(nums: Vec<i32>) -> bool {
3+
let check = |p: usize| -> bool {
4+
let mut prev = None;
5+
for j in 0..nums.len() {
6+
if p != j {
7+
if let Some(value) = prev {
8+
if value >= nums[j] {
9+
return false;
10+
}
11+
}
12+
prev = Some(nums[j]);
13+
}
14+
}
15+
true
16+
};
17+
for i in 1..nums.len() {
18+
if nums[i-1] >= nums[i] {
19+
return check(i-1) || check(i)
20+
}
21+
}
22+
true
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function canBeIncreasing(nums: number[]): boolean {
2+
const check = (p: number) => {
3+
let prev = undefined;
4+
for (let j = 0; j < nums.length; j++) {
5+
if (p != j) {
6+
if (prev !== undefined && prev >= nums[j]) {
7+
return false;
8+
}
9+
prev = nums[j];
10+
}
11+
}
12+
return true;
13+
};
14+
for (let i = 0; i < nums.length; i++) {
15+
if (nums[i - 1] >= nums[i]) {
16+
return check(i - 1) || check(i);
17+
}
18+
}
19+
return true;
20+
}

0 commit comments

Comments
 (0)