Skip to content

Commit 9649b7e

Browse files
add 3239
1 parent efd44e5 commit 9649b7e

File tree

2 files changed

+33
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

2 files changed

+33
-0
lines changed

paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
3+
| 3239 | [Minimum Number of Flips to Make Binary Grid Palindromic I](https://leetcode.com/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3239.java) | | Easy |
34
| 3238 | [Find the Number of Winning Players](https://leetcode.com/problems/find-the-number-of-winning-players/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3238.java) | | Easy |
45
| 3237 | [Alt and Tab Simulation](https://leetcode.com/problems/alt-and-tab-simulation/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3237.java) | | Medium |
56
| 3234 | [Count the Number of Substrings With Dominant Ones](https://leetcode.com/problems/count-the-number-of-substrings-with-dominant-ones/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3234.java) | | Medium | Sliding Window
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3239 {
4+
public static class Solution1 {
5+
public int minFlips(int[][] grid) {
6+
int m = grid.length;
7+
int n = grid[0].length;
8+
int ans = m * n;
9+
//try rows first
10+
int flips = 0;
11+
for (int i = 0; i < m; i++) {
12+
for (int left = 0, right = n - 1; left < right; left++, right--) {
13+
if (grid[i][left] != grid[i][right]) {
14+
flips++;
15+
}
16+
}
17+
}
18+
ans = Math.min(ans, flips);
19+
flips = 0;
20+
//try columns now
21+
for (int j = 0; j < n; j++) {
22+
for (int top = 0, bottom = m - 1; top < bottom; top++, bottom--) {
23+
if (grid[top][j] != grid[bottom][j]) {
24+
flips++;
25+
}
26+
}
27+
}
28+
ans = Math.min(flips, ans);
29+
return ans;
30+
}
31+
}
32+
}

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