9-Palindrome-Number

Fri 14 November 2025

https://leetcode.com/problems/palindrome-number

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isPalindrome(self, x: int) -> bool:
    if x < 0:
      return False

    rev = 0
    y = x

    while y:
      rev = rev * 10 + y % 10
      y //= 10

    return rev == x
new Solution …

Category: leetcode

Read More

9-Pygal-1

Fri 14 November 2025
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'

#!pip install pygal
!pip show pygal | grep "Version:"
Version: 3.0.5
import pygal

line_chart = pygal.Line()
line_chart.title = "Simple Line …

Category: plot-compare

Read More

90-Subsets-Ii

Fri 14 November 2025

https://leetcode.com/problems/subsets-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
    ans = []

    def dfs(s: int, path: List[int]) -> None:
      ans.append(path)
      if s == len(nums):
        return

      for i in …

Category: leetcode

Read More

902-Numbers-At-Most-N-Given-Digit-Set

Fri 14 November 2025

https://leetcode.com/problems/numbers-at-most-n-given-digit-set

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def atMostNGivenDigitSet(self, D: List[str], N: int) -> int:
    ans = 0
    num = str(N)

    for i in range(1, len(num)):
      ans += len(D)**i

    for i, c in …

Category: leetcode

Read More

904-Fruit-Into-Baskets

Fri 14 November 2025

https://leetcode.com/problems/fruit-into-baskets

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def totalFruit(self, tree: List[int]) -> int:
    ans = 0
    count = defaultdict(int)

    l = 0
    for r, t in enumerate(tree):
      count[t] += 1
      while len(count) > 2:
        count[tree …

Category: leetcode

Read More

905-Sort-Array-By-Parity

Fri 14 November 2025

https://leetcode.com/problems/sort-array-by-parity

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortArrayByParity(self, A: List[int]) -> List[int]:
    l = 0
    r = len(A) - 1

    while l < r:
      if A[l] % 2 == 1 and A[r] % 2 == 0:
        A[l …

Category: leetcode

Read More

906-Super-Palindromes

Fri 14 November 2025

https://leetcode.com/problems/super-palindromes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def superpalindromesInRange(self, left: str, right: str) -> int:
    def nextPalindrome(num: int) -> int:
      s = str(num)
      n = len(s)

      half = s[0:(n + 1) // 2]
      reversedHalf = half[:n // 2 …

Category: leetcode

Read More

907-Sum-Of-Subarray-Minimums

Fri 14 November 2025

https://leetcode.com/problems/sum-of-subarray-minimums

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sumSubarrayMins(self, arr: List[int]) -> int:
    kMod = 1_000_000_007
    n = len(arr)
    ans = 0
    # prev[i] := index k s.t. arr[k] is the prev min in arr …

Category: leetcode

Read More

908-Smallest-Range-I

Fri 14 November 2025

https://leetcode.com/problems/smallest-range-i

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def smallestRangeI(self, A: List[int], K: int) -> int:
    return max(0, max(A) - min(A) - 2 * K)
new Solution().smallestRangeI()

Score: 5

Category: leetcode

Read More

909-Snakes-And-Ladders

Fri 14 November 2025

https://leetcode.com/problems/snakes-and-ladders

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def snakesAndLadders(self, board: List[List[int]]) -> int:
    n = len(board)
    ans = 0
    q = deque([1])
    seen = set()
    A = [0] * (1 + n * n)  # 2D -> 1D

    for i …

Category: leetcode

Read More
Page 76 of 146

« Prev Next »