You are viewing a single comment's thread. Return to all comments →
C#
public static string balancedSums(List<int> arr) { var len = arr.Count; var total = arr.Sum(x => (long)x); long leftSum = 0; long rightSum = total; for (int i = 0; i < len; ++i) { rightSum = rightSum - arr[i]; var leftIndex = (i == 0) ? 0 : i - 1; if (i > 0) { leftSum = leftSum + arr[leftIndex]; } if (leftSum == rightSum) { return "YES"; } } return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Array
You are viewing a single comment's thread. Return to all comments →
C#