🟢 剑指 Offer II 012. 左右两边子数组的和相等
LeetCode 提示
题目难度 简单
原题链接 🔗 leetcode
#
题解1class Solution { public int pivotIndex(int[] nums) { int sum = 0, half = 0, right; for (int n : nums) { sum += n; } for (int i=0; i<nums.length; i+=1) { right = sum - half - nums[i]; if (right == half) { return i; } half += nums[i]; } return -1; }}