Sherlock and Array

  • + 0 comments

    Java:

    public static String balancedSums(List<Integer> arr) {
      int sum = 0;
      for (int i : arr) {
        sum += i;
      }
      int left = 0;
      for (int i = 0; i < arr.size(); i++) {
        int right = sum - left - arr.get(i);
        if (right == left) {
          return "YES";
        }
        left += arr.get(i);
      }
      return "NO";
    }