74-Search-A-2D-Matrix

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

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

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

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

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

75-Sort-Colors

Sat 17 May 2025

https://leetcode.com/problems/sort-colors

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortColors(self, nums: List[int]) -> None:
    zero = -1
    one = -1
    two = -1

    for num in nums:
      if num == 0:
        two += 1
        one += 1
        zero += 1
        nums[two] = 2 …

Category: leetcode

Read More

751-Ip-To-Cidr

Sat 17 May 2025

https://leetcode.com/problems/ip-to-cidr

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def ipToCIDR(self, ip: str, n: int) -> List[str]:
    ans = []
    num = self._getNum(ip.split('.'))

    while n > 0:
      lowbit = num & -num
      count = self._maxLow(n) if lowbit == 0 else …

Category: leetcode

Read More

753-Cracking-The-Safe

Sat 17 May 2025

https://leetcode.com/problems/cracking-the-safe

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def crackSafe(self, n: int, k: int) -> str:
    passwordSize = k**n
    path = '0' * n
    seen = set()
    seen.add(path)

    def dfs(path: str) -> str:
      if len(seen) == passwordSize:
        return …

Category: leetcode

Read More

754-Reach-A-Number

Sat 17 May 2025

https://leetcode.com/problems/reach-a-number

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reachNumber(self, target: int) -> int:
    ans = 0
    pos = 0
    target = abs(target)

    while pos < target:
      ans += 1
      pos += ans

    while (pos - target) & 1:
      ans += 1
      pos += ans

    return …

Category: leetcode

Read More

756-Pyramid-Transition-Matrix

Sat 17 May 2025

https://leetcode.com/problems/pyramid-transition-matrix

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def pyramidTransition(self, bottom: str, allowed: List[str]) -> bool:
    prefixToBlocks = defaultdict(list)

    for a in allowed:
      prefixToBlocks[a[:2]].append(a[2])

    def dfs(row: str, nextRow: str, i …

Category: leetcode

Read More
Page 56 of 77

« Prev Next »