Skip to content

Commit 12171e6

Browse files
committed
Updated 3345, 3346
1 parent 530929f commit 12171e6

File tree

2 files changed

+17
-12
lines changed
  • src/main/java/g3301_3400
    • s3345_smallest_divisible_digit_product_i
    • s3346_maximum_frequency_of_an_element_after_performing_operations_i

2 files changed

+17
-12
lines changed
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package g3301_3400.s3345_smallest_divisible_digit_product_i;
22

3-
// #Easy #2024_11_12_Time_1_ms_(59.15%)_Space_40.5_MB_(98.74%)
3+
// #Easy #Math #Enumeration #2024_11_13_Time_0_ms_(100.00%)_Space_41.2_MB_(29.77%)
44

55
public class Solution {
66
public int smallestNumber(int n, int t) {
7-
for (int i = n; i < 101; i++) {
8-
if (digProduct(i) % t == 0) {
9-
return i;
7+
int num = -1;
8+
int check = n;
9+
while (num == -1) {
10+
int product = findProduct(check);
11+
if (product % t == 0) {
12+
num = check;
1013
}
14+
check += 1;
1115
}
12-
return -1;
16+
return num;
1317
}
1418

15-
private int digProduct(int n) {
16-
int pro = 1;
17-
while (n > 0) {
18-
pro *= n % 10;
19-
n /= 10;
19+
private int findProduct(int check) {
20+
int res = 1;
21+
while (check > 0) {
22+
res *= check % 10;
23+
check = check / 10;
2024
}
21-
return pro;
25+
return res;
2226
}
2327
}

src/main/java/g3301_3400/s3346_maximum_frequency_of_an_element_after_performing_operations_i/Solution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3301_3400.s3346_maximum_frequency_of_an_element_after_performing_operations_i;
22

3-
// #Medium #2024_11_12_Time_7_ms_(96.72%)_Space_57.4_MB_(44.86%)
3+
// #Medium #Array #Sorting #Binary_Search #Prefix_Sum #Sliding_Window
4+
// #2024_11_13_Time_7_ms_(96.84%)_Space_56.4_MB_(92.35%)
45

56
public class Solution {
67
private int getMax(int[] nums) {

0 commit comments

Comments
 (0)