File tree 2 files changed +0
-27
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder
2 files changed +0
-27
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class _713 {
4
4
public static class Solution1 {
5
- /**
6
- * O(n^2) solution, accepted initially, then Leetcode added one test case to fail it.
7
- */
8
- public int numSubarrayProductLessThanK (int [] nums , int k ) {
9
- int result = 0 ;
10
- for (int i = 0 ; i < nums .length ; i ++) {
11
- int product = nums [i ];
12
- if (product < k ) {
13
- result ++;
14
- for (int j = i + 1 ; j < nums .length ; j ++) {
15
- product *= nums [j ];
16
- if (product < k ) {
17
- result ++;
18
- } else {
19
- break ;
20
- }
21
- }
22
- }
23
- }
24
- return result ;
25
- }
26
- }
27
-
28
- public static class Solution2 {
29
5
public int numSubarrayProductLessThanK (int [] nums , int k ) {
30
6
if (k < 2 ) {
31
7
return 0 ;
Original file line number Diff line number Diff line change 8
8
9
9
public class _713Test {
10
10
private static _713 .Solution1 solution1 ;
11
- private static _713 .Solution2 solution2 ;
12
11
private static int [] nums ;
13
12
private static int k ;
14
13
15
14
@ BeforeClass
16
15
public static void setup () {
17
- solution2 = new _713 .Solution2 ();
18
16
solution1 = new _713 .Solution1 ();
19
17
}
20
18
21
19
@ Test
22
20
public void test1 () {
23
21
nums = new int []{1 , 2 , 3 };
24
22
k = 0 ;
25
- assertEquals (0 , solution2 .numSubarrayProductLessThanK (nums , k ));
26
23
assertEquals (0 , solution1 .numSubarrayProductLessThanK (nums , k ));
27
24
}
28
25
You can’t perform that action at this time.
0 commit comments