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

Commita9c5c8e

Browse files
add 1727
1 parent3a62bc5 commita9c5c8e

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1727|[Largest Submatrix With Rearrangements](https://leetcode.com/problems/largest-submatrix-with-rearrangements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1727.java)||Medium|Greedy, Sort|
1112
|1726|[Tuple with Same Product](https://leetcode.com/problems/tuple-with-same-product/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1726.java)||Medium|Array|
1213
|1725|[Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1725.java)||Easy|Greedy|
1314
|1721|[Swapping Nodes in a Linked List](https://leetcode.com/problems/swapping-nodes-in-a-linked-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1721.java)||Medium|LinkedList|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1727 {
6+
publicstaticclassSolution1 {
7+
/**
8+
* credit: https://leetcode.com/problems/largest-submatrix-with-rearrangements/discuss/1020682/Java-or-6ms-or-easy-understanding-with-comments-and-images
9+
*/
10+
publicintlargestSubmatrix(int[][]matrix) {
11+
intm =matrix.length;
12+
intn =matrix[0].length;
13+
for (inti =1;i <m;i++) {
14+
for (intj =0;j <n;j++) {
15+
if (matrix[i][j] !=0) {
16+
matrix[i][j] =matrix[i -1][j] +1;
17+
}
18+
}
19+
}
20+
intcount =0;
21+
for (inti =0;i <m;i++) {
22+
Arrays.sort(matrix[i]);
23+
for (intj =1;j <=n;j++) {
24+
count =Math.max(count,j *matrix[i][n -j]);
25+
}
26+
}
27+
returncount;
28+
}
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.utils.CommonUtils;
4+
importcom.fishercoder.solutions._1;
5+
importcom.fishercoder.solutions._1727;
6+
importorg.junit.BeforeClass;
7+
importorg.junit.Test;
8+
9+
importstaticorg.junit.Assert.assertArrayEquals;
10+
importstaticorg.junit.Assert.assertEquals;
11+
12+
publicclass_1727Test {
13+
privatestatic_1727.Solution1solution1;
14+
15+
@BeforeClass
16+
publicstaticvoidsetup() {
17+
solution1 =new_1727.Solution1();
18+
}
19+
20+
@Test
21+
publicvoidtest1() {
22+
assertEquals(8,solution1.largestSubmatrix(
23+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[0,1,1,1,1,1,1],[1,1,0,1,1,0,1],[1,0,0,1,0,1,1]")));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp