lurenaa的博客

😂代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
int pivotIndex(vector<int>& nums) {
int tl = 0;
for(auto x : nums)
tl += x;
vector<int> tv(nums.size());
for(int i = 0; i < nums.size(); ++i) {
if(tv[i] == tl - nums[i] - tv[i])
return i;
if(i != nums.size() - 1)
tv[i + 1] = tv[i] + nums[i];
// cout << tv[i] << " ";
}
return -1;
}
};

Accepted

741/741 cases passed (28 ms)

Your runtime beats 54.54 % of cpp submissions

Your memory usage beats 7.04 % of cpp submissions (10.4 MB)