public class Solution
    {
        public int PivotIndex(int[] nums)
        {
            if (nums.Length == 0)
            {
                return -1;
            }
            var left = 0;
            var right = nums.Sum() - nums[0];
            if (left == right)
            {
                return 0;
            }
            for (int i = 1; i < nums.Length; i++)
            {
                left += nums[i - 1];
                right -= nums[i];
                if (left == right)
                {
                    return i;
                }
            }
            return -1;
        }
    }

 

posted on 2018-10-01 12:21  Sempron2800+  阅读(101)  评论(0编辑  收藏  举报