> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/02-24-2022-2104.md).

# 02/24/2022 2104

>

```
// Some code

class Solution { public long subArrayRanges(int[] nums) { if (nums == null || nums.length == 0) return 0L; final int N = nums.length; long sum = 0L; for (int i = 0; i < N; i++) { int min = nums[i], max = nums[i]; for (int j = i; j < N; j++) { min = Math.min(min, nums[j]); max = Math.max(max, nums[j]); sum += max - min; } } return sum; } }
```
