915. 分割数组
为保证权益,题目请参考 915. 分割数组(From LeetCode).
解决方案1
CPP
C++
//
// Created by lenovo on 2020/6/27.
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
int partitionDisjoint(vector<int> &A) {
int maxPos = 0;
int maxVau = A[0];
int curMax = A[0];
for (int i = 0; i < A.size(); ++i) {
curMax = max(curMax, A[i]);
if (A[i] < maxVau) {
maxPos = i;
maxVau = curMax;
}
}
return maxPos + 1;
}
};
int main() {
return 0;
}
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
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