Skip to content

Commit

Permalink
Create 370.Range-Addition.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Jul 25, 2018
1 parent 2fb3e73 commit 458070a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Segment_Tree/370.Range-Addition/370.Range-Addition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
vector<int> getModifiedArray(int length, vector<vector<int>>& updates)
{
vector<int>q(length+1,0);
for (int i=0; i<updates.size(); i++)
{
q[updates[i][0]]+=updates[i][2];
q[updates[i][1]+1]-=updates[i][2];
}

vector<int>results(length,0);
results[0] = q[0];
int count = q[0];
for (int i=1; i<length; i++)
{
count += q[i];
results[i] = count;
}
return results;
}
};

0 comments on commit 458070a

Please sign in to comment.