Skip to content

Commit 1d715a6

Browse files
committedApr 20, 2025
Add solution #1281
1 parent a99e8bb commit 1d715a6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,403 LeetCode solutions in JavaScript
1+
# 1,404 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -980,6 +980,7 @@
980980
1276|[Number of Burgers with No Waste of Ingredients](./solutions/1276-number-of-burgers-with-no-waste-of-ingredients.js)|Medium|
981981
1277|[Count Square Submatrices with All Ones](./solutions/1277-count-square-submatrices-with-all-ones.js)|Medium|
982982
1278|[Palindrome Partitioning III](./solutions/1278-palindrome-partitioning-iii.js)|Hard|
983+
1281|[Subtract the Product and Sum of Digits of an Integer](./solutions/1281-subtract-the-product-and-sum-of-digits-of-an-integer.js)|Easy|
983984
1282|[Group the People Given the Group Size They Belong To](./solutions/1282-group-the-people-given-the-group-size-they-belong-to.js)|Medium|
984985
1283|[Find the Smallest Divisor Given a Threshold](./solutions/1283-find-the-smallest-divisor-given-a-threshold.js)|Medium|
985986
1284|[Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](./solutions/1284-minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix.js)|Hard|
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 1281. Subtract the Product and Sum of Digits of an Integer
3+
* https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer number n, return the difference between the product of its digits and
7+
* the sum of its digits.
8+
*/
9+
10+
/**
11+
* @param {number} n
12+
* @return {number}
13+
*/
14+
var subtractProductAndSum = function(n) {
15+
let product = 1;
16+
let sum = 0;
17+
18+
while (n > 0) {
19+
const digit = n % 10;
20+
product *= digit;
21+
sum += digit;
22+
n = Math.floor(n / 10);
23+
}
24+
25+
return product - sum;
26+
};

0 commit comments

Comments
 (0)
Please sign in to comment.