class Solution {
public int[] runningSum(int[] nums) {
int[] ans = new int[nums.length];
ans[0] = nums[0];
for (int i = 1; i < nums.length; i++)
ans[i] = ans[i-1] + nums[i];
return ans;
}
}
//O(n) hashmaps C++ Two Sum leetcode
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int,int> map;
for(int i=0; i<=nums.size();i++){
int compliment=target-nums[i];
if(map.count(compliment)==1){
return {map[compliment],i};
}
else{
map[nums[i]]=i;
}
}
return {-1,-1};
}
};
public int[] RunningSum(int[] nums)
{
int sum = 0;
int[] result= new int[nums.Length];
for(int i = 0; i < nums.Length; i++)
{
sum += nums[i];
result[i] = sum;
}
return result;
}