Skip to content

Commit defdfd0

Browse files
[LEET-3402] add 3402
1 parent f557f7b commit defdfd0

File tree

3 files changed

+41
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+41
-0
lines changed

Diff for: paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
33
| 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy |
44
| 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy |
5+
| 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy |
56
| 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy |
67
| 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy |
78
| 3386 | [Button with Longest Push Time](https://leetcode.com/problems/button-with-longest-push-time/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3402 {
4+
public static class Solution1 {
5+
public int minimumOperations(int[][] grid) {
6+
int ops = 0;
7+
for (int j = 0; j < grid[0].length; j++) {
8+
for (int i = 1; i < grid.length; i++) {
9+
if (grid[i][j] <= grid[i - 1][j]) {
10+
ops += grid[i - 1][j] - grid[i][j] + 1;
11+
grid[i][j] = grid[i - 1][j] + 1;
12+
}
13+
}
14+
}
15+
return ops;
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions.fourththousand._3402;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class _3402Test {
11+
private _3402.Solution1 solution1;
12+
13+
@BeforeEach
14+
public void setup() {
15+
solution1 = new _3402.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
assertEquals(15, solution1.minimumOperations(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[3,2],[1,3],[3,4],[0,1]")));
21+
}
22+
}

0 commit comments

Comments
 (0)