Skip to content

Commit 2d3c5ba

Browse files
authored
Update 2104-sum-of-subarray-ranges.js
1 parent 303f4de commit 2d3c5ba

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2104-sum-of-subarray-ranges.js

+19
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@ const subArrayRanges = function(nums) {
1616
}
1717
return res
1818
};
19+
20+
// another
21+
22+
/**
23+
* @param {number[]} nums
24+
* @return {number}
25+
*/
26+
const subArrayRanges = function(nums) {
27+
let res = 0, n = nums.length
28+
for(let i = 0; i < n; i++) {
29+
let max = nums[i], min = nums[i]
30+
for(let j = i; j < n; j++) {
31+
max = Math.max(max, nums[j])
32+
min = Math.min(min, nums[j])
33+
res += max - min
34+
}
35+
}
36+
return res
37+
};

0 commit comments

Comments
 (0)