File tree Expand file tree Collapse file tree 4 files changed +152
-0
lines changed
solution/1900-1999/1909.Remove One Element to Make the Array Strictly Increasing Expand file tree Collapse file tree 4 files changed +152
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,60 @@ func check(nums []int, i int) bool {
163
163
}
164
164
```
165
165
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
+
166
220
### ** ...**
167
221
168
222
```
Original file line number Diff line number Diff line change @@ -149,6 +149,60 @@ func check(nums []int, i int) bool {
149
149
}
150
150
```
151
151
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
+
152
206
### ** ...**
153
207
154
208
```
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments