Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 713 Bytes

Question_2219.md

File metadata and controls

30 lines (24 loc) · 713 Bytes

LeetCode Records - Question 2219 Maximum Sum Score of Array

Attempt 1: Track the left sum and the right sum

class Solution {
    public long maximumSumScore(int[] nums) {
        long leftSum = 0;
        long rightSum = 0;
        for (int num : nums) {
            rightSum += num;
        }

        long maxScore = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            leftSum += nums[i];

            long score = Math.max(leftSum, rightSum);
            maxScore = Math.max(maxScore, score);

            rightSum -= nums[i];
        }

        return maxScore;
    }
}
  • Runtime: 1 ms (Beats: 100.00%)
  • Memory: 56.46 MB (Beats: 69.09%)