Skip to content

Commit 228d529

Browse files
solves subtract the product and sum of digits of an integer
1 parent 60a0a67 commit 228d529

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@
330330
| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | |
331331
| 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | |
332332
| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | |
333-
| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | | |
333+
| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | |
334334
| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | | |
335335
| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | | |
336336
| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class SubtractTheProductAndSumOfDigitsOfAnInteger {
2+
public int subtractProductAndSum(int n) {
3+
int product= 1, sum = 0, digit;
4+
while (n > 0) {
5+
digit = n % 10;
6+
product *= digit;
7+
sum += digit;
8+
n /= 10;
9+
}
10+
return product - sum;
11+
}
12+
}

0 commit comments

Comments
 (0)