Number Theory Others¶
Table of Contents¶
- 326. Power of Three (Easy)
- 633. Sum of Square Numbers (Medium)
- 279. Perfect Squares (Medium)
- 1015. Smallest Integer Divisible by K (Medium)
- 2240. Number of Ways to Buy Pens and Pencils (Medium)
- 2221. Find Triangular Sum of an Array (Medium)
326. Power of Three¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: math, recursion
633. Sum of Square Numbers¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, two pointers, binary search
279. Perfect Squares¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, dynamic programming, breadth first search
279. Perfect Squares - Python Solution
import math
# DP - Knapsack Unbounded
def numSquares(n: int) -> int:
dp = [float("inf") for _ in range(n + 1)]
dp[0] = 0
for i in range(1, n + 1):
for j in range(1, int(math.sqrt(n)) + 1):
dp[i] = min(dp[i], dp[i - j**2] + 1)
return dp[n]
n = 12
print(numSquares(n)) # 3
1015. Smallest Integer Divisible by K¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, math
2240. Number of Ways to Buy Pens and Pencils¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, enumeration
2221. Find Triangular Sum of an Array¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, simulation, combinatorics