726-Number-Of-Atoms

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

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

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

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

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

734-Sentence-Similarity

Sat 17 May 2025

https://leetcode.com/problems/sentence-similarity

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def areSentencesSimilar(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:
    if len(sentence1) != len(sentence2):
      return False

    # map[key] := all similar words of key
    map …

Category: leetcode

Read More

735-Asteroid-Collision

Sat 17 May 2025

https://leetcode.com/problems/asteroid-collision

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

    for a in asteroids:
      if a > 0:
        stack.append(a)
      else:  # A < 0
        # Destroy previous positive one(s)
        while stack …

Category: leetcode

Read More

736-Parse-Lisp-Expression

Sat 17 May 2025

https://leetcode.com/problems/parse-lisp-expression

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def evaluate(self, expression: str) -> int:
    def evaluate(e: str, prevScope: dict) -> int:
      if e[0].isdigit() or e[0] == '-':
        return int(e)
      if e in prevScope:
        return prevScope …

Category: leetcode

Read More

737-Sentence-Similarity-Ii

Sat 17 May 2025

https://leetcode.com/problems/sentence-similarity-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def areSentencesSimilarTwo(self, words1: List[str], words2: List[str], pairs: List[List[str]]) -> bool:
    if len(words1) != len(words2):
      return False

    # graph[key] := all similar words of key
    graph …

Category: leetcode

Read More

739-Daily-Temperatures

Sat 17 May 2025

https://leetcode.com/problems/daily-temperatures

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
    ans = [0] * len(temperatures)
    stack = []

    for i, t in enumerate(temperatures):
      while stack and t > temperatures[stack[-1]]:
        index = stack.pop …

Category: leetcode

Read More
Page 55 of 77

« Prev Next »