785-Is-Graph-Bipartite

Sat 17 May 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

Sat 17 May 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

Sat 17 May 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

Sat 17 May 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

Sat 17 May 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

79-Word-Search

Sat 17 May 2025

https://leetcode.com/problems/word-search

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def exist(self, board: List[List[str]], word: str) -> bool:
    m = len(board)
    n = len(board[0])

    def dfs(i: int, j: int, s: int) -> bool:
      if i < 0 …

Category: leetcode

Read More

790-Domino-And-Tromino-Tiling

Sat 17 May 2025

https://leetcode.com/problems/domino-and-tromino-tiling

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numTilings(self, N: int) -> int:
    kMod = 1_000_000_007
    dp = [0, 1, 2, 5] + [0] * 997

    for i in range(4, N + 1):
      dp[i] = 2 * dp[i - 1 …

Category: leetcode

Read More

791-Custom-Sort-String

Sat 17 May 2025

https://leetcode.com/problems/custom-sort-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def customSortString(self, S: str, T: str) -> str:
    ans = ""
    count = [0] * 26

    for c in T:
      count[ord(c) - ord('a')] += 1

    for c in S:
      while count[ord …

Category: leetcode

Read More

792-Number-Of-Matching-Subsequences

Sat 17 May 2025

https://leetcode.com/problems/number-of-matching-subsequences

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numMatchingSubseq(self, s: str, words: List[str]) -> int:
    root = {}

    def insert(word: str) -> None:
      node = root
      for c in word:
        if c not in node:
          node[c] = {'count …

Category: leetcode

Read More

794-Valid-Tic-Tac-Toe-State

Sat 17 May 2025

https://leetcode.com/problems/valid-tic-tac-toe-state

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def validTicTacToe(self, board: List[str]) -> bool:
    def isWin(c: chr) -> bool:
      return any(row.count(c) == 3 for row in board) or \
          any(row.count(c) == 3 for …

Category: leetcode

Read More
Page 59 of 77

« Prev Next »