File tree Expand file tree Collapse file tree 2 files changed +17
-12
lines changed
s3345_smallest_divisible_digit_product_i
s3346_maximum_frequency_of_an_element_after_performing_operations_i Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 1
1
package g3301_3400 .s3345_smallest_divisible_digit_product_i ;
2
2
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 %)
4
4
5
5
public class Solution {
6
6
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 ;
10
13
}
14
+ check += 1 ;
11
15
}
12
- return - 1 ;
16
+ return num ;
13
17
}
14
18
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 ;
20
24
}
21
- return pro ;
25
+ return res ;
22
26
}
23
27
}
Original file line number Diff line number Diff line change 1
1
package g3301_3400 .s3346_maximum_frequency_of_an_element_after_performing_operations_i ;
2
2
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%)
4
5
5
6
public class Solution {
6
7
private int getMax (int [] nums ) {
You can’t perform that action at this time.
0 commit comments