We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 303f4de commit 2d3c5baCopy full SHA for 2d3c5ba
2104-sum-of-subarray-ranges.js
@@ -16,3 +16,22 @@ const subArrayRanges = function(nums) {
16
}
17
return res
18
};
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