Skip to content

Commit 4c0f6a9

Browse files
refactor 713
1 parent 7cbfdbb commit 4c0f6a9

File tree

2 files changed

+0
-27
lines changed

2 files changed

+0
-27
lines changed

src/main/java/com/fishercoder/solutions/_713.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22

33
public class _713 {
44
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 {
295
public int numSubarrayProductLessThanK(int[] nums, int k) {
306
if (k < 2) {
317
return 0;

src/test/java/com/fishercoder/_713Test.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@
88

99
public class _713Test {
1010
private static _713.Solution1 solution1;
11-
private static _713.Solution2 solution2;
1211
private static int[] nums;
1312
private static int k;
1413

1514
@BeforeClass
1615
public static void setup() {
17-
solution2 = new _713.Solution2();
1816
solution1 = new _713.Solution1();
1917
}
2018

2119
@Test
2220
public void test1() {
2321
nums = new int[]{1, 2, 3};
2422
k = 0;
25-
assertEquals(0, solution2.numSubarrayProductLessThanK(nums, k));
2623
assertEquals(0, solution1.numSubarrayProductLessThanK(nums, k));
2724
}
2825

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy