当前位置:网站首页>Sword finger offer II 012 The sum of left and right subarrays is equal

Sword finger offer II 012 The sum of left and right subarrays is equal

2022-06-25 17:04:00 Python ml

The finger of the sword Offer II 012. The sum of the left and right subarrays is equal

class Solution {
    
public:
    int pivotIndex(vector<int>& nums) {
    
		int total=accumulate(nums.begin(),nums.end(),0);
		int sum=0;
		for(int i=0;i<nums.size();++i){
    
			if(2*sum+nums[i]==total)
				return i;
			sum+=nums[i];
		}
		return -1;
    }
};
原网站

版权声明
本文为[Python ml]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251635253216.html