734-Sentence-Similarity

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

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

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

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

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

74-Search-A-2D-Matrix

Fri 14 November 2025

https://leetcode.com/problems/search-a-2d-matrix

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
    if not matrix:
      return False

    m = len(matrix)
    n = len(matrix[0])
    l = 0
    r = m * n

    while l …

Category: leetcode

Read More

744-Find-Smallest-Letter-Greater-Than-Target

Fri 14 November 2025

https://leetcode.com/problems/find-smallest-letter-greater-than-target

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def nextGreatestLetter(self, letters: List[str], target: str) -> str:
    l = 0
    r = len(letters)

    while l < r:
      m = (l + r) >> 1
      if letters[m] <= target:
        l = m + 1
      else …

Category: leetcode

Read More

746-Min-Cost-Climbing-Stairs

Fri 14 November 2025

https://leetcode.com/problems/min-cost-climbing-stairs

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

    for i in range(2, len(cost)):
      cost[i] += min(cost[i - 1], cost[i - 2])

    return cost[-1 …

Category: leetcode

Read More

747-Largest-Number-At-Least-Twice-Of-Others

Fri 14 November 2025

https://leetcode.com/problems/largest-number-at-least-twice-of-others

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

    for i, num in enumerate(nums):
      if num > max:
        secondMax = max
        max = num
        ans = i
      elif num > secondMax …

Category: leetcode

Read More

748-Shortest-Completing-Word

Fri 14 November 2025

https://leetcode.com/problems/shortest-completing-word

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str:
    def isMatch(word: str) -> bool:
      wordCount = Counter(word)
      return False if any(wordCount[i] < count[i] for i in string …

Category: leetcode

Read More
Page 62 of 146

« Prev Next »