Skip to content

Commit c7c43dc

Browse files
authored
Create Maximum Product of Two Digits.java
1 parent 96a5d01 commit c7c43dc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int maxProduct(int n) {
3+
int maximum = Integer.MIN_VALUE;
4+
int secondMaximum = Integer.MIN_VALUE;
5+
while (n > 0) {
6+
int num = n % 10;
7+
n /= 10;
8+
if (num > maximum) {
9+
secondMaximum = maximum;
10+
maximum = num;
11+
} else if (num > secondMaximum) {
12+
secondMaximum = num;
13+
}
14+
}
15+
return maximum * secondMaximum;
16+
}
17+
}

0 commit comments

Comments
 (0)