@@ -55,21 +55,104 @@ No resulting array is strictly increasing, so return false.</pre>
55
55
<li><code>1 <= nums[i] <= 1000</code></li>
56
56
</ul >
57
57
58
-
59
58
## Solutions
60
59
61
60
<!-- tabs:start -->
62
61
63
62
### ** Python3**
64
63
65
64
``` python
66
-
65
+ class Solution :
66
+ def canBeIncreasing (self , nums : List[int ]) -> bool :
67
+ def check (nums , i ):
68
+ prev = float (' -inf' )
69
+ for j, num in enumerate (nums):
70
+ if i == j:
71
+ continue
72
+ if prev >= nums[j]:
73
+ return False
74
+ prev = nums[j]
75
+ return True
76
+
77
+ i, n = 1 , len (nums)
78
+ while i < n and nums[i - 1 ] < nums[i]:
79
+ i += 1
80
+ return check(nums, i - 1 ) or check(nums, i)
67
81
```
68
82
69
83
### ** Java**
70
84
71
85
``` java
86
+ class Solution {
87
+ public boolean canBeIncreasing (int [] nums ) {
88
+ int i = 1 , n = nums. length;
89
+ for (; i < n && nums[i - 1 ] < nums[i]; ++ i);
90
+ return check(nums, i - 1 ) || check(nums, i);
91
+ }
92
+
93
+ private boolean check (int [] nums , int i ) {
94
+ int prev = Integer . MIN_VALUE ;
95
+ for (int j = 0 ; j < nums. length; ++ j) {
96
+ if (i == j) {
97
+ continue ;
98
+ }
99
+ if (prev >= nums[j]) {
100
+ return false ;
101
+ }
102
+ prev = nums[j];
103
+ }
104
+ return true ;
105
+ }
106
+ }
107
+ ```
108
+
109
+ ### ** C++**
110
+
111
+ ``` cpp
112
+ class Solution {
113
+ public:
114
+ bool canBeIncreasing(vector<int >& nums) {
115
+ int i = 1, n = nums.size();
116
+ for (; i < n && nums[ i - 1] < nums[ i] ; ++i);
117
+ return check(nums, i - 1) || check(nums, i);
118
+ }
119
+
120
+ bool check(vector<int>& nums, int i) {
121
+ int prev = 0;
122
+ for (int j = 0; j < nums.size(); ++j) {
123
+ if (i == j) continue;
124
+ if (prev >= nums[j]) return false;
125
+ prev = nums[j];
126
+ }
127
+ return true ;
128
+ }
129
+ };
130
+ ```
72
131
132
+ ### ** Go**
133
+
134
+ ``` go
135
+ func canBeIncreasing (nums []int ) bool {
136
+ i , n := 1 , len (nums)
137
+ for ; i < n && nums[i-1 ] < nums[i]; i++ {
138
+
139
+ }
140
+ return check (nums, i-1 ) || check (nums, i)
141
+ }
142
+
143
+ func check (nums []int , i int ) bool {
144
+ prev := 0
145
+ for j := 0 ; j < len (nums); j++ {
146
+ if i == j {
147
+ continue
148
+ }
149
+ if prev >= nums[j] {
150
+ return false
151
+ }
152
+ prev = nums[j]
153
+ }
154
+ return true
155
+ }
73
156
```
74
157
75
158
### ** ...**
0 commit comments