79-Word-Search

Fri 14 November 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

Fri 14 November 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

Fri 14 November 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

Fri 14 November 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

Fri 14 November 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

795-Number-Of-Subarrays-With-Bounded-Maximum

Fri 14 November 2025

https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum

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

    for i, a in enumerate(A):
      if a > R:
        l = i
      if …

Category: leetcode

Read More

797-All-Paths-From-Source-To-Target

Fri 14 November 2025

https://leetcode.com/problems/all-paths-from-source-to-target

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

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

      for …

Category: leetcode

Read More

8-Panel-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 show panel | grep "Version:"
Version: 1.5.4
import panel as pn
import holoviews as hv
import numpy as np …

Category: plot-compare

Read More

8-String-To-Integer-Atoi

Fri 14 November 2025

https://leetcode.com/problems/string-to-integer-atoi

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def myAtoi(self, s: str) -> int:
    s = s.strip()
    if not s:
      return 0

    sign = -1 if s[0] == '-' else 1
    if s[0] in {'-', '+'}:
      s = s[1:]

    num …

Category: leetcode

Read More

80-Remove-Duplicates-From-Sorted-Array-Ii

Fri 14 November 2025

https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii

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

    for num in nums:
      if i < 2 or num != nums[i - 2]:
        nums[i] = num
        i += 1

    return i
new …

Category: leetcode

Read More
Page 66 of 146

« Prev Next »