356-Line-Reflection

Sat 17 May 2025

https://leetcode.com/problems/line-reflection

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isReflected(self, points: List[List[int]]) -> bool:
    minX = math.inf
    maxX = -math.inf
    seen = set()

    for x, y in points:
      minX = min(minX, x)
      maxX = max(maxX, x …

Category: leetcode

Read More

357-Count-Numbers-With-Unique-Digits

Sat 17 May 2025

https://leetcode.com/problems/count-numbers-with-unique-digits

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def countNumbersWithUniqueDigits(self, n: int) -> int:
    if n == 0:
      return 1

    ans = 10
    uniqueDigits = 9
    availableNum = 9

    while n > 1 and availableNum > 0:
      uniqueDigits *= availableNum
      ans += uniqueDigits
      n -= 1 …

Category: leetcode

Read More

358-Rearrange-String-K-Distance-Apart

Sat 17 May 2025

https://leetcode.com/problems/rearrange-string-k-distance-apart

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def rearrangeString(self, s: str, k: int) -> str:
    n = len(s)
    ans = []
    count = Counter(s)
    valid = Counter()  # valid[i] := the leftmost index i can appear

    # Returns the letter that …

Category: leetcode

Read More

36-Valid-Sudoku

Sat 17 May 2025

https://leetcode.com/problems/valid-sudoku

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isValidSudoku(self, board: List[List[str]]) -> bool:
    seen = set()

    for i in range(9):
      for j in range(9):
        c = board[i][j]
        if c == '.':
          continue
        if c …

Category: leetcode

Read More

360-Sort-Transformed-Array

Sat 17 May 2025

https://leetcode.com/problems/sort-transformed-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortTransformedArray(self, nums: List[int], a: int, b: int, c: int) -> List[int]:
    n = len(nums)
    upward = a > 0
    ans = [0] * n

    # The concavity of f only depends …

Category: leetcode

Read More

361-Bomb-Enemy

Sat 17 May 2025

https://leetcode.com/problems/bomb-enemy

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxKilledEnemies(self, grid: List[List[chr]]) -> int:
    m = len(grid)
    n = len(grid[0])
    enemyCount = 0
    # dp[i][j] := max enemies grid[i][j] can kill
    dp = [[0 …

Category: leetcode

Read More

365-Water-And-Jug-Problem

Sat 17 May 2025

https://leetcode.com/problems/water-and-jug-problem

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def canMeasureWater(self, jug1Capacity: int, jug2Capacity: int, targetCapacity: int) -> bool:
    return targetCapacity == 0 or \
        jug1Capacity + jug2Capacity >= targetCapacity and \
        targetCapacity % gcd(jug1Capacity, jug2Capacity) == 0
new Solution().canMeasureWater()

Score: 5

Category: leetcode

Read More

367-Valid-Perfect-Square

Sat 17 May 2025

https://leetcode.com/problems/valid-perfect-square

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isPerfectSquare(self, num: int) -> bool:
    l = 1
    r = num

    while l < r:
      m = (l + r) // 2
      if m >= num / m:
        r = m
      else:
        l = m + 1

    return l …

Category: leetcode

Read More

368-Largest-Divisible-Subset

Sat 17 May 2025

https://leetcode.com/problems/largest-divisible-subset

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def largestDivisibleSubset(self, nums: List[int]) -> List[int]:
    n = len(nums)
    ans = []
    count = [1] * n
    prevIndex = [-1] * n
    maxCount = 0
    index = -1

    nums.sort()

    for i, num in enumerate …

Category: leetcode

Read More

37-Sudoku-Solver

Sat 17 May 2025

https://leetcode.com/problems/sudoku-solver

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def solveSudoku(self, board: List[List[str]]) -> None:
    def isValid(row: int, col: int, c: chr) -> bool:
      for i in range(9):
        if board[i][col] == c or \
           board …

Category: leetcode

Read More
Page 30 of 77

« Prev Next »