Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a5a0f3

Browse files
authored
Merge pull requestneetcode-gh#2292 from a93a/main
Delete newer duplicate of Problem 665 in C++ and rename older contribution
2 parents303ea5b +a375e41 commit9a5a0f3

File tree

3 files changed

+18
-54
lines changed

3 files changed

+18
-54
lines changed

‎cpp/0665-Non-Decreasing-Array.cpp‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎cpp/0665-non-decreasing-array.cpp‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
classSolution {
22
public:
33
boolcheckPossibility(vector<int>& nums) {
4-
int count =0;
5-
for(int i=1;i<nums.size();i++){
6-
if(nums[i-1]>nums[i]){
7-
count++;
8-
if(i>=2&&nums[i-2]>nums[i]){
9-
nums[i]=nums[i-1];
10-
}
11-
else{
12-
nums[i-1]=nums[i];
13-
}
4+
bool changed =false;
5+
6+
for(int i =0; i < nums.size() -1; i++){
7+
if(nums[i] <= nums[i+1]){
8+
continue;
149
}
10+
if(changed){
11+
returnfalse;
12+
}
13+
14+
if(i ==0 || nums[i+1] >= nums[i-1]){
15+
nums[i] = nums[i+1];
16+
}
17+
else{
18+
nums[i+1] = nums[i];
19+
}
20+
changed =true;
1521
}
16-
return count<=1;
22+
23+
returntrue;
1724
}
1825
};

‎cpp/665-Non-decreasing-Array.cpp‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp