Class Solution
java.lang.Object
g2601_2700.s2614_prime_in_diagonal.Solution
2614 - Prime In Diagonal.<p>Easy</p>
<p>You are given a 0-indexed two-dimensional integer array <code>nums</code>.</p>
<p>Return <em>the largest <strong>prime</strong> number that lies on at least one of the <strong>diagonals</strong> of</em> <code>nums</code>. In case, no prime is present on any of the diagonals, return <em>0.</em></p>
<p>Note that:</p>
<ul>
<li>An integer is <strong>prime</strong> if it is greater than <code>1</code> and has no positive integer divisors other than <code>1</code> and itself.</li>
<li>An integer <code>val</code> is on one of the <strong>diagonals</strong> of <code>nums</code> if there exists an integer <code>i</code> for which <code>nums[i][i] = val</code> or an <code>i</code> for which <code>nums[i][nums.length - i - 1] = val</code>.</li>
</ul>
<p><img src="https://assets.leetcode.com/uploads/2023/03/06/screenshot-2023-03-06-at-45648-pm.png" alt="" /></p>
<p>In the above diagram, one diagonal is <strong>[1,5,9]</strong> and another diagonal is <strong>[3,5,7]</strong>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [[1,2,3],[5,6,7],[9,10,11]]</p>
<p><strong>Output:</strong> 11</p>
<p><strong>Explanation:</strong> The numbers 1, 3, 6, 9, and 11 are the only numbers present on at least one of the diagonals. Since 11 is the largest prime, we return 11.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [[1,2,3],[5,17,7],[9,11,10]]</p>
<p><strong>Output:</strong> 17</p>
<p><strong>Explanation:</strong> The numbers 1, 3, 9, 10, and 17 are all present on at least one of the diagonals. 17 is the largest prime, so we return 17.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 300</code></li>
<li><code>nums.length == nums<sub>i</sub>.length</code></li>
<li><code>1 <= nums[i][j] <= 4*10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
diagonalPrime
public int diagonalPrime(int[][] nums)
-