Skip to content

Commit

Permalink
0907 codes updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyubobobo committed Sep 16, 2018
1 parent dce7921 commit d4ca6bb
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions 0907-Sum-of-Subarray-Minimums/cpp-0907/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,25 @@ class Solution {
int n = A.size();

vector<int> s;
long long repeat = 0;

vector<int> rSmaller(n, n);
for(int i = 0; i < n ; i ++){
if(s.empty() || A[i] > A[s.back()])
s.push_back(i);
else{
while(!s.empty() && A[s.back()] >= A[i]){
rSmaller[s.back()] = i;
s.pop_back();
}
s.push_back(i);
while(!s.empty() && A[s.back()] >= A[i]){
rSmaller[s.back()] = i;
s.pop_back();
}
s.push_back(i);
}
// Solution::print_vec(rSmaller);

s.clear();
vector<int> lSmaller(n, -1);
int r = n - 1;
for(int i = n - 1; i >= 0; i --){
if(s.empty() || A[i] > A[s.back()])
s.push_back(i);
else{
while(!s.empty() && A[s.back()] > A[i]){
lSmaller[s.back()] = i;
s.pop_back();
}
s.push_back(i);
while(!s.empty() && A[s.back()] > A[i]){
lSmaller[s.back()] = i;
s.pop_back();
}
s.push_back(i);
}
// Solution::print_vec(lSmaller);

Expand Down

0 comments on commit d4ca6bb

Please sign in to comment.