/**
* Problem: LeetCode 3536 - Maximum Product of Two Digits
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public int maxProduct(int n) {
int first = 0;
int second = 0;
while (n > 0) {
int digit = n % 10;
if (digit >= first) {
second = first;
first = digit;
} else if (digit > second) {
second = digit;
}
n /= 10;
}
return first * second;
}
}
"""
Problem: LeetCode 3536 - Maximum Product of Two Digits
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
class Solution:
def maxProduct(self, n: int) -> int:
first = 0
second = 0
while n > 0:
digit = n % 10
if digit >= first:
second = first
first = digit
elif digit > second:
second = digit
n //= 10
return first * second
/**
* Problem: LeetCode 3536 - Maximum Product of Two Digits
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
class Solution {
public:
int maxProduct(int n) {
int first = 0;
int second = 0;
while (n > 0) {
int digit = n % 10;
if (digit >= first) {
second = first;
first = digit;
} else if (digit > second) {
second = digit;
}
n /= 10;
}
return first * second;
}
};
/**
* Problem: LeetCode 3536 - Maximum Product of Two Digits
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
var maxProduct = function(n) {
let first = 0;
let second = 0;
while (n > 0) {
const digit = n % 10;
if (digit >= first) {
second = first;
first = digit;
} else if (digit > second) {
second = digit;
}
n = Math.floor(n / 10);
}
return first * second;
};