Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 748 Bytes

Question_3345.md

File metadata and controls

34 lines (28 loc) · 748 Bytes

LeetCode Records - Question 3345 Smallest Divisible Digit Product I

Attempt 1: Test every case

class Solution {
    public int smallestNumber(int n, int t) {
        int productOfDigits = getProductOfDigits(n);
        while (productOfDigits % t != 0) {
            n++;
            productOfDigits = getProductOfDigits(n);
        }

        return n;
    }

    private int getProductOfDigits(int n) {
        if (n == 0) {
            return 0;
        }

        int productOfDigits = 1;
        while (n > 0) {
            productOfDigits *= n % 10;
            n /= 10;
        }
        
        return productOfDigits;
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.28 MB (Beats: 100.00%)