return 3
One for loop to calculate sum, then another loop to compare (sum-nums[j]-leftsum)==leftsum?
if true return j, if false, then update leftsum=sum-nums[j]
public int PivotIndex(int[] nums)
{
if (nums == null || nums.Length == )
{
return -;
}
int l = nums.Length;
int sum = ; int leftsum = ;
for (int i = ; i < l; i++)
{
sum +=nums[i];
}
for (int j=; j< l; j++)
{
if (sum - nums[j] - leftsum == leftsum)
{
return j;
}
else
leftsum += nums[j];
}
return -;
}