660-Remove-9

Fri 14 November 2025

https://leetcode.com/problems/remove-9

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def newInteger(self, n: int) -> int:
    ans = []
    while n:
      ans.append(str(n % 9))
      n //= 9
    return ''.join(reversed(ans))
new Solution().newInteger()

Score: 5

Category: leetcode

Read More

661-Image-Smoother

Fri 14 November 2025

https://leetcode.com/problems/image-smoother

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def imageSmoother(self, M: List[List[int]]) -> List[List[int]]:
    m = len(M)
    n = len(M[0])
    ans = [[0 for j in range(n)] for i in range(m …

Category: leetcode

Read More

663-Equal-Tree-Partition

Fri 14 November 2025

https://leetcode.com/problems/equal-tree-partition

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def checkEqualTree(self, root: Optional[TreeNode]) -> bool:
    if not root:
      return False

    seen = set()

    def dfs(root: Optional[TreeNode]) -> int:
      if not root:
        return 0

      summ = root.val + dfs …

Category: leetcode

Read More

665-Non-Decreasing-Array

Fri 14 November 2025

https://leetcode.com/problems/non-decreasing-array

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

    for i in range(len(nums) - 1):
      if nums[i] > nums[i + 1]:
        if j is not None:
          return False …

Category: leetcode

Read More

666-Path-Sum-Iv

Fri 14 November 2025

https://leetcode.com/problems/path-sum-iv

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def pathSum(self, nums: List[int]) -> int:
    ans = 0
    tree = [[-1] * 8 for _ in range(4)]

    for num in nums:
      d = num // 100 - 1
      p = (num % 100) // 10 …

Category: leetcode

Read More

667-Beautiful-Arrangement-Ii

Fri 14 November 2025

https://leetcode.com/problems/beautiful-arrangement-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def constructArray(self, n: int, k: int) -> List[int]:
    ans = list(range(1, n - k + 1))

    for i in range(k):
      if i % 2 == 0:
        ans.append(n - i …

Category: leetcode

Read More

67-Add-Binary

Fri 14 November 2025

https://leetcode.com/problems/add-binary

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def addBinary(self, a: str, b: str) -> str:
    s = []
    carry = 0
    i = len(a) - 1
    j = len(b) - 1

    while i >= 0 or j >= 0 or carry:
      if i …

Category: leetcode

Read More

670-Maximum-Swap

Fri 14 November 2025

https://leetcode.com/problems/maximum-swap

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maximumSwap(self, num: int) -> int:
    s = list(str(num))
    dict = {c: i for i, c in enumerate(s)}

    for i, c in enumerate(s):
      for digit in reversed …

Category: leetcode

Read More

672-Bulb-Switcher-Ii

Fri 14 November 2025

https://leetcode.com/problems/bulb-switcher-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def flipLights(self, n: int, m: int) -> int:
    n = min(n, 3)

    if m == 0:
      return 1
    if m == 1:
      return [2, 3, 4][n - 1]
    if m == 2 …

Category: leetcode

Read More

673-Number-Of-Longest-Increasing-Subsequence

Fri 14 November 2025

https://leetcode.com/problems/number-of-longest-increasing-subsequence

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findNumberOfLIS(self, nums: List[int]) -> int:
    ans = 0
    maxLength = 0
    length = [1] * len(nums)  # length[i] := LIS's length ending w/ nums[i]
    count = [1] * len(nums)  # count …

Category: leetcode

Read More
Page 50 of 77

« Prev Next »