java.lang.Object
g2501_2600.s2574_left_and_right_sum_differences.Solution

public class Solution extends Object
2574 - Left and Right Sum Differences.<p>Easy</p> <p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a <strong>0-indexed</strong> integer array <code>answer</code> where:</p> <ul> <li><code>answer.length == nums.length</code>.</li> <li><code>answer[i] = |leftSum[i] - rightSum[i]|</code>.</li> </ul> <p>Where:</p> <ul> <li><code>leftSum[i]</code> is the sum of elements to the left of the index <code>i</code> in the array <code>nums</code>. If there is no such element, <code>leftSum[i] = 0</code>.</li> <li><code>rightSum[i]</code> is the sum of elements to the right of the index <code>i</code> in the array <code>nums</code>. If there is no such element, <code>rightSum[i] = 0</code>.</li> </ul> <p>Return <em>the array</em> <code>answer</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [10,4,8,3]</p> <p><strong>Output:</strong> [15,1,11,22]</p> <p><strong>Explanation:</strong> The array leftSum is [0,10,14,22] and the array rightSum is [15,11,3,0]. The array answer is [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1]</p> <p><strong>Output:</strong> [0]</p> <p><strong>Explanation:</strong> The array leftSum is [0] and the array rightSum is [0]. The array answer is [|0 - 0|] = [0].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 1000</code></li> <li><code>1 <= nums[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • leftRightDifference

      public int[] leftRightDifference(int[] nums)