Skip to content

Commit fd412e8

Browse files
committed
feat: add c solution to lc problem: No.0769
No.0769.Max Chunks To Make Sorted
1 parent f242eff commit fd412e8

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/0700-0799/0769.Max Chunks To Make Sorted/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@ func maxChunksToSorted(arr []int) int {
215215
}
216216
```
217217

218+
### **C**
219+
220+
```c
221+
#define max(a,b) (((a) > (b)) ? (a) : (b))
222+
223+
int maxChunksToSorted(int *arr, int arrSize) {
224+
int res = 0;
225+
int mx = -1;
226+
for (int i = 0; i < arrSize; i++) {
227+
mx = max(mx, arr[i]);
228+
if (mx == i) {
229+
res++;
230+
}
231+
}
232+
return res;
233+
}
234+
```
235+
218236
### **TypeScript**
219237
220238
```ts

solution/0700-0799/0769.Max Chunks To Make Sorted/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ func maxChunksToSorted(arr []int) int {
189189
}
190190
```
191191

192+
### **C**
193+
194+
```c
195+
#define max(a,b) (((a) > (b)) ? (a) : (b))
196+
197+
int maxChunksToSorted(int *arr, int arrSize) {
198+
int res = 0;
199+
int mx = -1;
200+
for (int i = 0; i < arrSize; i++) {
201+
mx = max(mx, arr[i]);
202+
if (mx == i) {
203+
res++;
204+
}
205+
}
206+
return res;
207+
}
208+
```
209+
192210
### **TypeScript**
193211
194212
```ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define max(a,b) (((a) > (b)) ? (a) : (b))
2+
3+
int maxChunksToSorted(int *arr, int arrSize) {
4+
int res = 0;
5+
int mx = -1;
6+
for (int i = 0; i < arrSize; i++) {
7+
mx = max(mx, arr[i]);
8+
if (mx == i) {
9+
res++;
10+
}
11+
}
12+
return res;
13+
}

0 commit comments

Comments
 (0)