-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNon decreasing array.cpp
More file actions
45 lines (39 loc) · 957 Bytes
/
Non decreasing array.cpp
File metadata and controls
45 lines (39 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Platform :- Leetcode
Problem :- Non Decreasing Array
*/
class Solution {
public:
bool checkPossibility(vector<int>& nums) {
int f=0;
int c=0;
vector<int>z=nums;
for(int i=1;i<z.size();++i){
if(z[i]<z[i-1]){
z[i]=z[i-1];
c=i;
break;
}
}
// cout<<z[0]<<" ";
for(int i=1;i<z.size();++i){
// cout<<z[i]<<" ";
if(z[i]>=z[i-1])continue;
f=1;break;
}
// cout<<endl;
if(f==0)return true;
vector<int>temp=nums;
temp[c-1]=temp[c];
f=0;
// cout<<temp[0]<<" ";
for(int i=1;i<temp.size();++i){
//cout<<temp[i]<<" ";
if(temp[i]>=temp[i-1])continue;
f=1;break;
}
// cout<<endl;
if(f)return false;
return true;
}
};