Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
partition-array-into-disjoint-intervals.cpp 427 Bytes
Copy Edit Raw Blame History
kamyu authored 2018-09-30 19:50 +08:00 . Create partition-array-into-disjoint-intervals.cpp
// Time: O(n)
// Space: O(n)
class Solution {
public:
int partitionDisjoint(vector<int>& A) {
vector<int> B(A);
for (int i = A.size() - 2; i > 0; --i) {
B[i] = min(B[i], B[i + 1]);
}
int p_max = 0;
for (int i = 1; i < A.size(); ++i) {
p_max = max(p_max, A[i - 1]);
if (p_max <= B[i]) {
return i;
}
}
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search