Skip to content

Commit 65b7eb9

Browse files
committed
Add solution #2535
1 parent eeaf182 commit 65b7eb9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
2482|[Difference Between Ones and Zeros in Row and Column](./2482-difference-between-ones-and-zeros-in-row-and-column.js)|Medium|
333333
2490|[Circular Sentence](./2490-circular-sentence.js)|Easy|
334334
2529|[Maximum Count of Positive Integer and Negative Integer](./2529-maximum-count-of-positive-integer-and-negative-integer.js)|Easy|
335+
2535|[Difference Between Element Sum and Digit Sum of an Array](./2535-difference-between-element-sum-and-digit-sum-of-an-array.js)|Easy|
335336

336337
## License
337338

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 2535. Difference Between Element Sum and Digit Sum of an Array
3+
* https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array/
4+
* Difficulty: Easy
5+
*
6+
* You are given a positive integer array nums:
7+
* - The element sum is the sum of all the elements in nums.
8+
* - The digit sum is the sum of all the digits (not necessarily distinct)
9+
* that appear in nums.
10+
*
11+
* Return the absolute difference between the element sum and digit sum of nums.
12+
* Note that the absolute difference between two integers x and y is defined
13+
* as |x - y|.
14+
*/
15+
16+
/**
17+
* @param {number[]} nums
18+
* @return {number}
19+
*/
20+
var differenceOfSum = function(nums) {
21+
const sum = input => input.reduce((sum, n) => sum + +n, 0);
22+
return Math.abs(sum(nums) - sum(nums.join('').split('')));
23+
};

0 commit comments

Comments
 (0)