Created
October 25, 2018 15:25
-
-
Save fpdjsns/906064f24f55e7ad159cd45b4fc64049 to your computer and use it in GitHub Desktop.
[leetcode] 915. Partition Array into Disjoint Intervals : https://leetcode.com/problems/partition-array-into-disjoint-intervals/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int partitionDisjoint(vector<int>& A) { | |
int size = A.size(); | |
vector<int> minArr(size); | |
minArr[size-1] = A[size-1]; | |
for(int i=size-2;i>=0;i--){ | |
minArr[i] = min(A[i], minArr[i+1]); | |
} | |
int maxNum=A[0]; | |
int ans = 0; | |
while(ans+1 < size && maxNum > minArr[ans+1]){ | |
ans++; | |
maxNum = max(maxNum, A[ans]); | |
} | |
return ans + 1; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment