Math Others¶
Table of Contents¶
- 1523. Count Odd Numbers in an Interval Range (Easy)
- 2829. Determine the Minimum Sum of a k-avoiding Array (Medium)
- 2579. Count Total Number of Colored Cells (Medium)
- 2834. Find the Minimum Possible Sum of a Beautiful Array (Medium)
- 1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K (Medium)
- 319. Bulb Switcher (Medium)
- 1780. Check if Number is a Sum of Powers of Three (Medium)
- 3091. Apply Operations to Make Sum of Array Greater Than or Equal to k (Medium)
- 2310. Sum of Numbers With Units Digit K (Medium)
- 2844. Minimum Operations to Make a Special Number (Medium)
- 2541. Minimum Operations to Make Array Equal II (Medium)
- 2195. Append K Integers With Minimal Sum (Medium)
- 2457. Minimum Addition to Make Integer Beautiful (Medium)
- 1017. Convert to Base -2 (Medium)
- 1954. Minimum Garden Perimeter to Collect Enough Apples (Medium)
- 1073. Adding Two Negabinary Numbers (Medium)
- 1823. Find the Winner of the Circular Game (Medium)
- 166. Fraction to Recurring Decimal (Medium)
- 3012. Minimize Length of Array Using Operations (Medium)
- 483. Smallest Good Base (Hard)
- 972. Equal Rational Numbers (Hard)
- 1862. Sum of Floored Pairs (Hard)
- 1739. Building Boxes (Hard)
- 2443. Sum of Number and Its Reverse (Medium)
- 1806. Minimum Number of Operations to Reinitialize a Permutation (Medium)
- 458. Poor Pigs (Hard)
- 60. Permutation Sequence (Hard)
- 2117. Abbreviating the Product of a Range (Hard)
- 660. Remove 9 (Hard) 👑
- 2979. Most Expensive Item That Can Not Be Bought (Medium) 👑
- 2647. Color the Triangle Red (Hard) 👑
1523. Count Odd Numbers in an Interval Range¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: math
2829. Determine the Minimum Sum of a k-avoiding Array¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, greedy
def minimumSum(n: int, k: int) -> int:
m = min(k // 2, n)
return (m * (m + 1) + (k * 2 + n - m - 1) * (n - m)) // 2
if __name__ == "__main__":
n = 5
k = 4
print(minimumSum(n, k)) # 18
2579. Count Total Number of Colored Cells¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math
2834. Find the Minimum Possible Sum of a Beautiful Array¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, greedy
1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, greedy
319. Bulb Switcher¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, brainteaser
1780. Check if Number is a Sum of Powers of Three¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math
3091. Apply Operations to Make Sum of Array Greater Than or Equal to k¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, greedy, enumeration
2310. Sum of Numbers With Units Digit K¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, dynamic programming, greedy, enumeration
2844. Minimum Operations to Make a Special Number¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, string, greedy, enumeration
2541. Minimum Operations to Make Array Equal II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, greedy
2195. Append K Integers With Minimal Sum¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, greedy, sorting
2457. Minimum Addition to Make Integer Beautiful¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, greedy
1017. Convert to Base -2¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math
1954. Minimum Garden Perimeter to Collect Enough Apples¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, binary search
1073. Adding Two Negabinary Numbers¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math
1823. Find the Winner of the Circular Game¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, recursion, queue, simulation
166. Fraction to Recurring Decimal¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, math, string
# Math
def fractionToDecimal(numerator: int, denominator: int) -> str:
if numerator == 0:
return "0"
res = []
if (numerator < 0) ^ (denominator < 0):
res.append("-")
numerator, denominator = abs(numerator), abs(denominator)
# Integer part
res.append(str(numerator // denominator))
remainder = numerator % denominator
if remainder == 0:
return "".join(res)
res.append(".")
# Dictionary to store remainders and their corresponding indices
remainder_map = {}
while remainder != 0:
if remainder in remainder_map:
res.insert(remainder_map[remainder], "(")
res.append(")")
break
remainder_map[remainder] = len(res)
remainder *= 10
res.append(str(remainder // denominator))
remainder %= denominator
return "".join(res)
numerator = 4
denominator = 333
print(fractionToDecimal(numerator, denominator)) # 0.(012)
3012. Minimize Length of Array Using Operations¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, greedy, number theory
483. Smallest Good Base¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, binary search
972. Equal Rational Numbers¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, string
1862. Sum of Floored Pairs¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, binary search, prefix sum
1739. Building Boxes¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, binary search, greedy
2443. Sum of Number and Its Reverse¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, enumeration
1806. Minimum Number of Operations to Reinitialize a Permutation¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, simulation
458. Poor Pigs¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, dynamic programming, combinatorics
60. Permutation Sequence¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, recursion
2117. Abbreviating the Product of a Range¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math
660. Remove 9¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math
2979. Most Expensive Item That Can Not Be Bought¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, dynamic programming, number theory
2647. Color the Triangle Red¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math