72-Edit-Distance

Fri 14 November 2025

https://leetcode.com/problems/edit-distance

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minDistance(self, word1: str, word2: str) -> int:
    m = len(word1)
    n = len(word2)
    # dp[i][j] := min # Of operations to convert word1[0..i) to word2[0..j …

Category: leetcode

Read More

720-Longest-Word-In-Dictionary

Fri 14 November 2025

https://leetcode.com/problems/longest-word-in-dictionary

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

    for word in words:
      node = root
      for c in word:
        if c not in node:
          node[c] = {}
        node = node[c]
      node …

Category: leetcode

Read More

722-Remove-Comments

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def removeComments(self, source: List[str]) -> List[str]:
    ans = []
    commenting = False
    modified = ''

    for line in source:
      i = 0
      while i < len(line):
        if i + 1 == len(line):
          if not …

Category: leetcode

Read More

724-Find-Pivot-Index

Fri 14 November 2025

https://leetcode.com/problems/find-pivot-index

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

    for i, num in enumerate(nums):
      if prefix == summ - prefix - num:
        return i
      prefix += num

    return -1 …

Category: leetcode

Read More

725-Split-Linked-List-In-Parts

Fri 14 November 2025

https://leetcode.com/problems/split-linked-list-in-parts

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def splitListToParts(self, root: ListNode, k: int) -> List[ListNode]:
    ans = [[] for _ in range(k)]
    length = 0
    curr = root
    while curr:
      length += 1
      curr = curr.next
    subLength = length // k …

Category: leetcode

Read More

726-Number-Of-Atoms

Fri 14 November 2025

https://leetcode.com/problems/number-of-atoms

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def countOfAtoms(self, formula: str) -> str:
    def parse() -> dict:
      ans = defaultdict(int)

      nonlocal i
      while i < n:
        if formula[i] == '(':
          i += 1
          for elem, freq in parse().items():
            ans …

Category: leetcode

Read More

728-Self-Dividing-Numbers

Fri 14 November 2025

https://leetcode.com/problems/self-dividing-numbers

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def selfDividingNumbers(self, left: int, right: int) -> List[int]:
    return [num for num in range(left, right + 1) if all(n != 0 and num % n == 0 for n in …

Category: leetcode

Read More

73-Set-Matrix-Zeroes

Fri 14 November 2025

https://leetcode.com/problems/set-matrix-zeroes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def setZeroes(self, matrix: List[List[int]]) -> None:
    m = len(matrix)
    n = len(matrix[0])
    shouldFillFirstRow = 0 in matrix[0]
    shouldFillFirstCol = 0 in list(zip(*matrix))[0]

    # Store the …

Category: leetcode

Read More

730-Count-Different-Palindromic-Subsequences

Fri 14 November 2025

https://leetcode.com/problems/count-different-palindromic-subsequences

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def countPalindromicSubsequences(self, s: str) -> int:
    def count(l: int, r: int) -> int:
      if l > r:
        return 0
      if l == r:
        return 1
      key = l * len(s) + r
      if …

Category: leetcode

Read More

733-Flood-Fill

Fri 14 November 2025

https://leetcode.com/problems/flood-fill

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def floodFill(self, image: List[List[int]],
                sr: int, sc: int, newColor: int) -> List[List[int]]:
    startColor = image[sr][sc]
    seen = set()

    def dfs(i: int, j: int) -> None …

Category: leetcode

Read More
Page 61 of 146

« Prev Next »