776-Split-Bst

Fri 14 November 2025

https://leetcode.com/problems/split-bst

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def splitBST(self, root: Optional[TreeNode], target: int) -> List[Optional[TreeNode]]:
    if not root:
      return None, None
    if root.val > target:
      left, right = self.splitBST(root.left, target)
      root …

Category: leetcode

Read More

78-Subsets

Fri 14 November 2025

https://leetcode.com/problems/subsets

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

    def dfs(s: int, path: List[int]) -> None:
      ans.append(path)

      for i in range(s, len(nums)):
        dfs …

Category: leetcode

Read More

780-Reaching-Points

Fri 14 November 2025

https://leetcode.com/problems/reaching-points

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:
    while sx < tx and sy < ty:
      tx, ty = tx % ty, ty % tx

    return sx == tx and sy …

Category: leetcode

Read More

781-Rabbits-In-Forest

Fri 14 November 2025

https://leetcode.com/problems/rabbits-in-forest

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

    for answer in answers:
      if count[answer] % (answer + 1) == 0:
        ans += answer + 1
      count[answer] += 1

    return ans …

Category: leetcode

Read More

782-Transform-To-Chessboard

Fri 14 November 2025

https://leetcode.com/problems/transform-to-chessboard

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

    if any(board[0][0] ^ board[i][0] ^ board[0][j] ^ board[i][j] for i in range …

Category: leetcode

Read More

785-Is-Graph-Bipartite

Fri 14 November 2025

https://leetcode.com/problems/is-graph-bipartite

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
from enum import Enum


class Color(Enum):
  kWhite = 0
  kRed = 1
  kGreen = 2


class Solution:
  def isBipartite(self, graph: List[List[int]]) -> bool:
    colors = [Color.kWhite] * len(graph)

    for i in …

Category: leetcode

Read More

786-K-Th-Smallest-Prime-Fraction

Fri 14 November 2025

https://leetcode.com/problems/k-th-smallest-prime-fraction

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

    while True:
      m = (l + r) / 2
      ans[0] = 0 …

Category: leetcode

Read More

787-Cheapest-Flights-Within-K-Stops

Fri 14 November 2025

https://leetcode.com/problems/cheapest-flights-within-k-stops

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findCheapestPrice(self, n: int, flights: List[List[int]], src: int, dst: int, k: int) -> int:
    graph = [[] for _ in range(n)]
    minHeap = [(0, src, k + 1)]  # (d, u …

Category: leetcode

Read More

788-Rotated-Digits

Fri 14 November 2025

https://leetcode.com/problems/rotated-digits

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def rotatedDigits(self, N: int) -> int:
    def isGoodNumber(i: int) -> bool:
      isRotated = False

      for c in str(i):
        if c == '0' or c == '1' or c == '8':
          continue
        if …

Category: leetcode

Read More

789-Escape-The-Ghosts

Fri 14 November 2025

https://leetcode.com/problems/escape-the-ghosts

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool:
    ghostSteps = min(abs(x - target[0]) +
                     abs(y - target[1]) for x, y in ghosts)

    return abs(target …

Category: leetcode

Read More
Page 65 of 146

« Prev Next »