max_prime
to 0 to keep track of the largest prime number found on the diagonals.i
from 0 to the length of nums
minus 1.
i
, check if nums[i][i]
(main diagonal) is a prime number. If it is, update max_prime
if it's larger than the current max_prime
.nums[i][nums.length - i - 1]
(secondary diagonal) is a prime number. If it is, update max_prime
if it's larger than the current max_prime
.max_prime
as the result.