830-Positions-Of-Large-Groups

Sat 17 May 2025

https://leetcode.com/problems/positions-of-large-groups

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def largeGroupPositions(self, S: str) -> List[List[int]]:
    n = len(S)
    ans = []
    i = 0
    j = 0

    while i < n:
      while j < n and S[j] == S[i]:
        j += 1 …

Category: leetcode

Read More

831-Masking-Personal-Information

Sat 17 May 2025

https://leetcode.com/problems/masking-personal-information

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maskPII(self, S: str) -> str:
    atIndex = S.find('@')
    if atIndex != -1:
      S = S.lower()
      return S[0] + '*' * 5 + S[atIndex - 1:]

    ans = ''.join(c for c in S …

Category: leetcode

Read More

832-Flipping-An-Image

Sat 17 May 2025

https://leetcode.com/problems/flipping-an-image

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

    for i in range(n):
      for j in range((n + 2) // 2):
        A[i][j], A …

Category: leetcode

Read More

833-Find-And-Replace-In-String

Sat 17 May 2025

https://leetcode.com/problems/find-and-replace-in-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findReplaceString(self, s: str, indexes: List[int],
                        sources: List[str], targets: List[str]) -> str:
    for index, source, target in sorted(zip(indexes, sources, targets), reverse=True):
      if s …

Category: leetcode

Read More

834-Sum-Of-Distances-In-Tree

Sat 17 May 2025

https://leetcode.com/problems/sum-of-distances-in-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
    ans = [0] * N
    count = [1] * N
    tree = defaultdict(set)

    for u, v in edges:
      tree[u].add(v …

Category: leetcode

Read More

835-Image-Overlap

Sat 17 May 2025

https://leetcode.com/problems/image-overlap

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def largestOverlap(self, A: List[List[int]], B: List[List[int]]) -> int:
    n = len(A)
    magic = 100
    onesA = []
    onesB = []
    dict = defaultdict(int)

    for i in range(n):
      for j …

Category: leetcode

Read More

836-Rectangle-Overlap

Sat 17 May 2025

https://leetcode.com/problems/rectangle-overlap

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
    return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1 …

Category: leetcode

Read More

837-New-21-Game

Sat 17 May 2025

https://leetcode.com/problems/new-21-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def new21Game(self, n: int, k: int, maxPts: int) -> float:
    # When the game ends, the point is in [k..k - 1 + maxPts]
    #   P = 1, if n >= k - 1 + maxPts …

Category: leetcode

Read More

838-Push-Dominoes

Sat 17 May 2025

https://leetcode.com/problems/push-dominoes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def pushDominoes(self, dominoes: str) -> str:
    ans = list(dominoes)
    L = -1
    R = -1

    for i in range(len(dominoes) + 1):
      if i == len(dominoes) or dominoes[i] == 'R':
        if …

Category: leetcode

Read More

84-Largest-Rectangle-In-Histogram

Sat 17 May 2025

https://leetcode.com/problems/largest-rectangle-in-histogram

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

    for i in range(len(heights) + 1):
      while stack and (i == len(heights) or heights[stack[-1]] > heights[i …

Category: leetcode

Read More
Page 63 of 77

« Prev Next »