leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1991.cpp (326B)


      1 class Solution {
      2   public:
      3     int findMiddleIndex(vector<int> &nums) {
      4         int left = 0;
      5         int right = accumulate(nums.begin(), nums.end(), 0);
      6         for (int i = 0; i < nums.size(); left += nums[i++]) {
      7             right -= nums[i];
      8             if (left == right) return i;
      9         }
     10         return -1;
     11     }
     12 };