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

Commit d057514

Browse files
feat: add solutions to lc problem: No.3523 (#4363)
No.3523.Make Array Non-decreasing
1 parent 76abd67 commit d057514

File tree

7 files changed

+167
-6
lines changed

7 files changed

+167
-6
lines changed

‎solution/3500-3599/3523.Make Array Non-decreasing/README.md‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,79 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3523.Ma
7575
#### Python3
7676

7777
```python
78-
78+
class Solution:
79+
def maximumPossibleSize(self, nums: List[int]) -> int:
80+
ans = mx = 0
81+
for x in nums:
82+
if mx <= x:
83+
ans += 1
84+
mx = x
85+
return ans
7986
```
8087

8188
#### Java
8289

8390
```java
84-
91+
class Solution {
92+
public int maximumPossibleSize(int[] nums) {
93+
int ans = 0, mx = 0;
94+
for (int x : nums) {
95+
if (mx <= x) {
96+
++ans;
97+
mx = x;
98+
}
99+
}
100+
return ans;
101+
}
102+
}
85103
```
86104

87105
#### C++
88106

89107
```cpp
90-
108+
class Solution {
109+
public:
110+
int maximumPossibleSize(vector<int>& nums) {
111+
int ans = 0, mx = 0;
112+
for (int x : nums) {
113+
if (mx <= x) {
114+
++ans;
115+
mx = x;
116+
}
117+
}
118+
return ans;
119+
}
120+
};
91121
```
92122
93123
#### Go
94124
95125
```go
126+
func maximumPossibleSize(nums []int) int {
127+
ans, mx := 0, 0
128+
for _, x := range nums {
129+
if mx <= x {
130+
ans++
131+
mx = x
132+
}
133+
}
134+
return ans
135+
}
136+
```
96137

138+
#### TypeScript
139+
140+
```ts
141+
function maximumPossibleSize(nums: number[]): number {
142+
let [ans, mx] = [0, 0];
143+
for (const x of nums) {
144+
if (mx <= x) {
145+
++ans;
146+
mx = x;
147+
}
148+
}
149+
return ans;
150+
}
97151
```
98152

99153
<!-- tabs:end -->

‎solution/3500-3599/3523.Make Array Non-decreasing/README_EN.md‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,79 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3523.Ma
7171
#### Python3
7272

7373
```python
74-
74+
class Solution:
75+
def maximumPossibleSize(self, nums: List[int]) -> int:
76+
ans = mx = 0
77+
for x in nums:
78+
if mx <= x:
79+
ans += 1
80+
mx = x
81+
return ans
7582
```
7683

7784
#### Java
7885

7986
```java
80-
87+
class Solution {
88+
public int maximumPossibleSize(int[] nums) {
89+
int ans = 0, mx = 0;
90+
for (int x : nums) {
91+
if (mx <= x) {
92+
++ans;
93+
mx = x;
94+
}
95+
}
96+
return ans;
97+
}
98+
}
8199
```
82100

83101
#### C++
84102

85103
```cpp
86-
104+
class Solution {
105+
public:
106+
int maximumPossibleSize(vector<int>& nums) {
107+
int ans = 0, mx = 0;
108+
for (int x : nums) {
109+
if (mx <= x) {
110+
++ans;
111+
mx = x;
112+
}
113+
}
114+
return ans;
115+
}
116+
};
87117
```
88118
89119
#### Go
90120
91121
```go
122+
func maximumPossibleSize(nums []int) int {
123+
ans, mx := 0, 0
124+
for _, x := range nums {
125+
if mx <= x {
126+
ans++
127+
mx = x
128+
}
129+
}
130+
return ans
131+
}
132+
```
92133

134+
#### TypeScript
135+
136+
```ts
137+
function maximumPossibleSize(nums: number[]): number {
138+
let [ans, mx] = [0, 0];
139+
for (const x of nums) {
140+
if (mx <= x) {
141+
++ans;
142+
mx = x;
143+
}
144+
}
145+
return ans;
146+
}
93147
```
94148

95149
<!-- tabs:end -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int maximumPossibleSize(vector<int>& nums) {
4+
int ans = 0, mx = 0;
5+
for (int x : nums) {
6+
if (mx <= x) {
7+
++ans;
8+
mx = x;
9+
}
10+
}
11+
return ans;
12+
}
13+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
func maximumPossibleSize(nums []int) int {
2+
ans, mx := 0, 0
3+
for _, x := range nums {
4+
if mx <= x {
5+
ans++
6+
mx = x
7+
}
8+
}
9+
return ans
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int maximumPossibleSize(int[] nums) {
3+
int ans = 0, mx = 0;
4+
for (int x : nums) {
5+
if (mx <= x) {
6+
++ans;
7+
mx = x;
8+
}
9+
}
10+
return ans;
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def maximumPossibleSize(self, nums: List[int]) -> int:
3+
ans = mx = 0
4+
for x in nums:
5+
if mx <= x:
6+
ans += 1
7+
mx = x
8+
return ans
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function maximumPossibleSize(nums: number[]): number {
2+
let [ans, mx] = [0, 0];
3+
for (const x of nums) {
4+
if (mx <= x) {
5+
++ans;
6+
mx = x;
7+
}
8+
}
9+
return ans;
10+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /