766-Toeplitz-Matrix

Fri 14 November 2025

https://leetcode.com/problems/toeplitz-matrix

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
    for i in range(len(matrix) - 1):
      for j in range(len(matrix[0]) - 1):
        if matrix[i][j] != matrix[i …

Category: leetcode

Read More

767-Reorganize-String

Fri 14 November 2025

https://leetcode.com/problems/reorganize-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reorganizeString(self, s: str) -> str:
    count = Counter(s)
    if max(count.values()) > (len(s) + 1) // 2:
      return ''

    ans = []
    maxHeap = [(-freq, c) for c, freq in count.items()]
    heapq …

Category: leetcode

Read More

768-Max-Chunks-To-Make-Sorted-Ii

Fri 14 November 2025

https://leetcode.com/problems/max-chunks-to-make-sorted-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxChunksToSorted(self, arr: List[int]) -> int:
    n = len(arr)
    ans = 0
    maxi = -math.inf
    mini = [arr[-1]] * n

    for i in reversed(range(n - 1)):
      mini[i] = min …

Category: leetcode

Read More

769-Max-Chunks-To-Make-Sorted

Fri 14 November 2025

https://leetcode.com/problems/max-chunks-to-make-sorted

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxChunksToSorted(self, arr: List[int]) -> int:
    ans = 0
    maxi = -math.inf

    for i, a in enumerate(arr):
      maxi = max(maxi, a)
      if maxi == i:
        ans += 1

    return ans …

Category: leetcode

Read More

77-Combinations

Fri 14 November 2025

https://leetcode.com/problems/combinations

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

    def dfs(s: int, path: List[int]) -> None:
      if len(path) == k:
        ans.append(path.copy())
        return

      for …

Category: leetcode

Read More

770-Basic-Calculator-Iv

Fri 14 November 2025

https://leetcode.com/problems/basic-calculator-iv

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Poly:
  def __init__(self, term: str = None, coef: int = None):
    if term and coef:
      self.terms = Counter({term: coef})
    else:
      self.terms = Counter()

  def __add__(self, other):
    for …

Category: leetcode

Read More

771-Jewels-And-Stones

Fri 14 November 2025

https://leetcode.com/problems/jewels-and-stones

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numJewelsInStones(self, J: str, S: str) -> int:
    jewels = set(J)
    return sum(s in jewels for s in S)
new Solution().numJewelsInStones()

Score: 5

Category: leetcode

Read More

772-Basic-Calculator-Iii

Fri 14 November 2025

https://leetcode.com/problems/basic-calculator-iii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def calculate(self, s: str) -> int:
    nums = []
    ops = []

    def calc():
      b = nums.pop()
      a = nums.pop()
      op = ops.pop()
      if op == '+':
        nums.append(a + b)
      elif op == '-':
        nums.append …

Category: leetcode

Read More

774-Minimize-Max-Distance-To-Gas-Station

Fri 14 November 2025

https://leetcode.com/problems/minimize-max-distance-to-gas-station

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minmaxGasDist(self, stations: List[int], k: int) -> float:
    kErr = 1e-6
    l = 0
    r = stations[-1] - stations[0]

    # True if can use k or less gas stations to ensure …

Category: leetcode

Read More

775-Global-And-Local-Inversions

Fri 14 November 2025

https://leetcode.com/problems/global-and-local-inversions

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isIdealPermutation(self, A: List[int]) -> bool:
    for i, a in enumerate(A):
      if abs(a - i) > 1:
        return False

    return True
new Solution().isIdealPermutation()

Score: 5

Category: leetcode

Read More
Page 64 of 146

« Prev Next »