75-Sort-Colors

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

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

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

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

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

758-Bold-Words-In-String

Fri 14 November 2025

https://leetcode.com/problems/bold-words-in-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def boldWords(self, words: List[str], s: str) -> str:
    n = len(s)
    ans = []
    # bold[i] := True if s[i] should be bolded
    bold = [0] * n

    boldEnd = -1  # s[i …

Category: leetcode

Read More

759-Employee-Free-Time

Fri 14 November 2025

https://leetcode.com/problems/employee-free-time

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def employeeFreeTime(self, schedule: '[[Interval]]') -> '[Interval]':
    ans = []
    intervals = []

    for s in schedule:
      intervals.extend(s)

    intervals.sort(key=lambda x: x.start)

    prevEnd = intervals[0].end

    for interval in …

Category: leetcode

Read More

76-Minimum-Window-Substring

Fri 14 November 2025

https://leetcode.com/problems/minimum-window-substring

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minWindow(self, s: str, t: str) -> str:
    count = Counter(t)
    required = len(t)
    bestLeft = -1
    minLength = len(s) + 1

    l = 0
    for r, c in enumerate(s):
      count …

Category: leetcode

Read More

761-Special-Binary-String

Fri 14 November 2025

https://leetcode.com/problems/special-binary-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def makeLargestSpecial(self, S: str) -> str:
    specials = []
    count = 0

    i = 0
    for j, c in enumerate(S):
      count += 1 if c == '1' else -1
      if count == 0:
        specials.append …

Category: leetcode

Read More

763-Partition-Labels

Fri 14 November 2025

https://leetcode.com/problems/partition-labels

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def partitionLabels(self, S: str) -> List[int]:
    ans = []
    letterToRightmostIndex = {c: i for i, c in enumerate(S)}

    l = 0
    r = 0

    for i, c in enumerate(S):
      r = max …

Category: leetcode

Read More
Page 63 of 146

« Prev Next »