diff --git "a/leetcode3/\355\231\251\354\235\200\354\247\200/3982. Sum of Integers with Maximum Digit Range.js" "b/leetcode3/\355\231\251\354\235\200\354\247\200/3982. Sum of Integers with Maximum Digit Range.js" new file mode 100644 index 00000000..2005d2e7 --- /dev/null +++ "b/leetcode3/\355\231\251\354\235\200\354\247\200/3982. Sum of Integers with Maximum Digit Range.js" @@ -0,0 +1,27 @@ +/** + * @param {number[]} nums + * @return {number} + */ +var maxDigitRange = function (nums) { + let maxDigitRange = 0; + let maxSet = []; + + for (const num of nums) { + const str = String(num); + let largest = "0"; + let smallest = "9"; + for (const digit of str) { + largest = Math.max(digit, largest); + smallest = Math.min(digit, smallest); + } + const digitRange = largest - smallest; + if (digitRange > maxDigitRange) { + maxDigitRange = digitRange; + maxSet = [num]; + } else if (digitRange === maxDigitRange) { + maxSet.push(num); + } + } + + return maxSet.reduce((cur, acc) => cur + acc, 0); +};