Skip to content

Commit b8ac792

Browse files
add 2614
1 parent 267e27a commit b8ac792

File tree

2 files changed

+36
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src/main/java/com/fishercoder/solutions/thirdthousand

2 files changed

+36
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2643.java) | | Easy |
2929
| 2641 | [Cousins in Binary Tree II](https://leetcode.com/problems/cousins-in-binary-tree-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2641.java) | | Medium |Tree, BFS, HashTable
3030
| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2639.java) | | Easy |
31+
| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2614.java) | | Easy |
3132
| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2605.java) | | Easy |
3233
| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2609.java) | | Easy |
3334
| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2600.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2614 {
4+
public static class Solution1 {
5+
public int diagonalPrime(int[][] nums) {
6+
int ans = 0;
7+
boolean[] nonPrimes = generatePrimes((int) (Math.pow(10, 6) * 4));
8+
for (int i = 0; i < nums.length; i++) {
9+
for (int j = 0; j < nums[0].length; j++) {
10+
if (i == j || i == nums.length - j - 1) {
11+
if (!nonPrimes[nums[i][j]]) {
12+
ans = Math.max(ans, nums[i][j]);
13+
}
14+
}
15+
}
16+
}
17+
return ans;
18+
}
19+
20+
private boolean[] generatePrimes(int n) {
21+
boolean[] nonPrimes = new boolean[n];
22+
//1 is not a prime number
23+
nonPrimes[1] = true;
24+
for (int i = 2; i < n; i++) {
25+
if (!nonPrimes[i]) {
26+
for (int j = 2; i * j < n; j++) {
27+
nonPrimes[i * j] = true;
28+
}
29+
}
30+
}
31+
return nonPrimes;
32+
}
33+
34+
}
35+
}

0 commit comments

Comments
 (0)