Leetcode 724 Solution
This article provides solution to leetcode question 724 (find-pivot-index)
Access this page by simply typing in "lcs 724" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/find-pivot-index
Solution
class Solution {
public:
int pivotIndex(vector<int>& nums) {
int s = 0;
for (int num: nums)
s += num;
int curr_sum = 0;
for (int i = 0; i < nums.size(); i++)
{
if (curr_sum * 2 + nums[i] == s)
return i;
curr_sum += nums[i];
}
return -1;
}
};