Prime Check¶
Table of Contents¶
- 3115. Maximum Prime Difference (Medium)
- 2614. Prime In Diagonal (Easy)
- 762. Prime Number of Set Bits in Binary Representation (Easy)
- 3044. Most Frequent Prime (Medium)
- 866. Prime Palindrome (Medium)
3115. Maximum Prime Difference¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, number theory
2614. Prime In Diagonal¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: array, math, matrix, number theory
2614. Prime In Diagonal - Python Solution
from math import isqrt
from typing import List
# Prime
def diagonalPrime(nums: List[List[int]]) -> int:
def is_prime(n):
if n <= 1:
return False
for i in range(2, isqrt(n) + 1):
if n % i == 0:
return False
return True
res = 0
for i, row in enumerate(nums):
for x in row[i], row[-1 - i]:
if x > res and is_prime(x):
res = x
return res
if __name__ == "__main__":
nums = [[1, 2, 3], [5, 6, 7], [9, 10, 11]]
print(diagonalPrime(nums)) # 11
762. Prime Number of Set Bits in Binary Representation¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: math, bit manipulation
3044. Most Frequent Prime¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, hash table, math, matrix, counting, enumeration, number theory
866. Prime Palindrome¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, number theory