Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita113b6d

Browse files
committed
238 (3) add some comments
1 parent13cd026 commita113b6d

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

‎src/_238_ProductOfArrayExceptSelf/Solution.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
/** see test {@link _238_ProductOfArrayExceptSelf.SolutionTest } */
2727
publicclassSolution {
2828

29-
// cache product of left subarray
29+
// res[i] = A[i - 1] * B[i + 1]
30+
// where A[i - 1] = nums[0] * nums[1] * .. * nums[i - 1]
31+
// B[i + 1] = nums[i + 1] * nums[i + 2] * .. nums[len - 1]
3032
publicint[]productExceptSelf(int[]nums) {
3133
intn =nums.length;
3234
int[]res =newint[n];

‎test/_238_ProductOfArrayExceptSelf/PracticeTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ public void tearDown() throws Exception {
2828

2929
@Test
3030
publicvoidTest1() {
31-
int[]nums = {1,2,3,4};
31+
int[]nums = {1,2,3,4};
3232
int[]actuals =solution.productExceptSelf(nums);
33-
int[]expecteds =newint[]{24,12,8,6};
33+
int[]expecteds ={24,12,8,6};
3434
assertArrayEquals(expecteds,actuals);
3535
}
3636

3737
@Test
3838
publicvoidTest2() {
39-
int[]nums = {1,2};
39+
int[]nums = {1,2};
4040
int[]actuals =solution.productExceptSelf(nums);
41-
int[]expecteds =newint[]{2,1};
41+
int[]expecteds = {2,1 };
42+
assertArrayEquals(expecteds,actuals);
43+
}
44+
45+
@Test
46+
publicvoidTest3() {
47+
int[]nums = {6 };
48+
int[]actuals =solution.productExceptSelf(nums);
49+
int[]expecteds = {1 };
4250
assertArrayEquals(expecteds,actuals);
4351
}
4452

‎test/_238_ProductOfArrayExceptSelf/SolutionLinearSpaceTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ public void tearDown() throws Exception {
2828

2929
@Test
3030
publicvoidTest1() {
31-
int[]nums = {1,2,3,4};
31+
int[]nums = {1,2,3,4};
3232
int[]actuals =solution.productExceptSelf(nums);
33-
int[]expecteds =newint[]{24,12,8,6};
33+
int[]expecteds ={24,12,8,6};
3434
assertArrayEquals(expecteds,actuals);
3535
}
3636

3737
@Test
3838
publicvoidTest2() {
39-
int[]nums = {1,2};
39+
int[]nums = {1,2};
4040
int[]actuals =solution.productExceptSelf(nums);
41-
int[]expecteds =newint[]{2,1};
41+
int[]expecteds = {2,1 };
42+
assertArrayEquals(expecteds,actuals);
43+
}
44+
45+
@Test
46+
publicvoidTest3() {
47+
int[]nums = {6 };
48+
int[]actuals =solution.productExceptSelf(nums);
49+
int[]expecteds = {1 };
4250
assertArrayEquals(expecteds,actuals);
4351
}
4452

‎test/_238_ProductOfArrayExceptSelf/SolutionTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
importorg.junit.rules.Timeout;
1010

1111
publicclassSolutionTest {
12-
12+
1313
/** Test method for {@link _238_ProductOfArrayExceptSelf.Solution } */
1414
Solutionsolution;
1515

@@ -28,17 +28,25 @@ public void tearDown() throws Exception {
2828

2929
@Test
3030
publicvoidTest1() {
31-
int[]nums = {1,2,3,4};
31+
int[]nums = {1,2,3,4};
3232
int[]actuals =solution.productExceptSelf(nums);
33-
int[]expecteds =newint[]{24,12,8,6};
33+
int[]expecteds ={24,12,8,6};
3434
assertArrayEquals(expecteds,actuals);
3535
}
3636

3737
@Test
3838
publicvoidTest2() {
39-
int[]nums = {1,2};
39+
int[]nums = {1,2 };
40+
int[]actuals =solution.productExceptSelf(nums);
41+
int[]expecteds = {2,1 };
42+
assertArrayEquals(expecteds,actuals);
43+
}
44+
45+
@Test
46+
publicvoidTest3() {
47+
int[]nums = {6 };
4048
int[]actuals =solution.productExceptSelf(nums);
41-
int[]expecteds =newint[]{2,1};
49+
int[]expecteds ={1};
4250
assertArrayEquals(expecteds,actuals);
4351
}
4452

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp