-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path915.cpp
51 lines (48 loc) · 1.51 KB
/
915.cpp
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
46
47
48
49
50
51
__________________________________________________________________________________________________
sample 16 ms submission
static int x = []() { ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
class Solution {
public:
int partitionDisjoint(vector<int>& A) {
int runningMax = A[0];
int candidate = 0;
int tempMax = A[0];
for(int i=1;i<A.size();i++){
if(A[i]<runningMax){
candidate = i;
continue;
}
//cout<<"Got "<<A[i]<<" max being "<<runningMax<<endl;
while(i<A.size() && A[i]>=runningMax){
//cout<<"Got "<<A[i]<<" tempmax being "<<tempMax<<endl;
tempMax=max(tempMax,A[i]);
++i;
}
if(i>=A.size())break;
runningMax=tempMax;
candidate = i;
}
return candidate+1;
}
};
__________________________________________________________________________________________________
sample 11024 kb submission
class Solution {
public:
int partitionDisjoint(vector<int>& A) {
int max_now = A[0];
int allmax = A[0];
int res = 1;
for(int i=0;i<A.size();i++){
if(A[i] < max_now){
res = i+1;
max_now = allmax;
}
else{
allmax = max(allmax,A[i]);
}
}
return res;
}
};
__________________________________________________________________________________________________