656-Coin-Path

Fri 14 November 2025

https://leetcode.com/problems/coin-path

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def cheapestJump(self, coins: List[int], maxJump: int) -> List[int]:
    if coins[-1] == -1:
      return []

    n = len(coins)
    # dp[i] := min cost to jump from i to n - 1 …

Category: leetcode

Read More

657-Robot-Return-To-Origin

Fri 14 November 2025

https://leetcode.com/problems/robot-return-to-origin

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def judgeCircle(self, moves: str) -> bool:
    return moves.count('R') == moves.count('L') and moves.count('U') == moves.count('D')
new Solution().judgeCircle()

Score: 5

Category: leetcode

Read More

658-Find-K-Closest-Elements

Fri 14 November 2025

https://leetcode.com/problems/find-k-closest-elements

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

    while l < r:
      m = (l + r) // 2
      if x - arr[m …

Category: leetcode

Read More

66-Plus-One

Fri 14 November 2025

https://leetcode.com/problems/plus-one

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def plusOne(self, digits: List[int]) -> List[int]:
    for i, d in reversed(list(enumerate(digits))):
      if d < 9:
        digits[i] += 1
        return digits
      digits[i] = 0

    return [1 …

Category: leetcode

Read More

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
Page 56 of 146

« Prev Next »