Skip to content

Commit

Permalink
Create 1964.Find-the-Longest-Valid-Obstacle-Course-at-Each-Position.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Aug 11, 2021
1 parent b3ddab0 commit a9aa00b
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public:
vector<int> longestObstacleCourseAtEachPosition(vector<int>& obstacles)
{
vector<int>a;
vector<int>rets;
for (auto x: obstacles)
{
if (a.empty() || a.back()<= x)
{
a.push_back(x);
rets.push_back(a.size());
}
else
{
auto iter = upper_bound(a.begin(), a.end(), x);
*iter = x;
rets.push_back(iter - a.begin() + 1);
}
}
return rets;
}
};

0 comments on commit a9aa00b

Please sign in to comment.