961-N-Repeated-Element-In-Size-2N-Array

Fri 14 November 2025

https://leetcode.com/problems/n-repeated-element-in-size-2n-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def repeatedNTimes(self, A: List[int]) -> int:
    for i in range(len(A) - 2):
      if A[i] == A[i + 1] or A[i] == A[i + 2]:
        return A[i …

Category: leetcode

Read More

962-Maximum-Width-Ramp

Fri 14 November 2025

https://leetcode.com/problems/maximum-width-ramp

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

    for i, num in enumerate(nums):
      if stack == [] or num <= nums[stack[-1]]:
        stack.append(i)

    for i, num …

Category: leetcode

Read More

963-Minimum-Area-Rectangle-Ii

Fri 14 November 2025

https://leetcode.com/problems/minimum-area-rectangle-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minAreaFreeRect(self, points: List[List[int]]) -> float:
    ans = math.inf
    # For each A, B pair points, {hash(A, B): (ax, ay, bx, by)}
    centerToPoints = defaultdict(list)

    for ax …

Category: leetcode

Read More

964-Least-Operators-To-Express-Number

Fri 14 November 2025

https://leetcode.com/problems/least-operators-to-express-number

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def leastOpsExpressTarget(self, x: int, target: int) -> int:
    @functools.lru_cache(None)
    def dfs(target):
      if x > target:
        return min(2 * target - 1, 2 * (x - target))
      if x == target:
        return …

Category: leetcode

Read More

966-Vowel-Spellchecker

Fri 14 November 2025

https://leetcode.com/problems/vowel-spellchecker

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:
    def lowerKey(word: str) -> str:
      return '$' + ''.join([c.lower() for c in word])

    def vowelKey(word: str) -> str …

Category: leetcode

Read More

969-Pancake-Sorting

Fri 14 November 2025

https://leetcode.com/problems/pancake-sorting

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

    for target in range(len(A), 0, -1):
      index = A.index(target)
      A[:index + 1] = A[:index + 1][::-1]
      A …

Category: leetcode

Read More

97-Interleaving-String

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isInterleave(self, s1: str, s2: str, s3: str) -> bool:
    m = len(s1)
    n = len(s2)
    if m + n != len(s3):
      return False

    # dp[i][j] := true if s3 …

Category: leetcode

Read More

970-Powerful-Integers

Fri 14 November 2025

https://leetcode.com/problems/powerful-integers

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
    xs = {x**i for i in range(20) if x**i < bound}
    ys = {y**i for i in …

Category: leetcode

Read More

972-Equal-Rational-Numbers

Fri 14 November 2025

https://leetcode.com/problems/equal-rational-numbers

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isRationalEqual(self, S: str, T: str) -> bool:
    def valueOf(s: str) -> float:
      if s.find('(') == -1:
        return float(s)

      integer_nonRepeating = float(s[:s.find('(')])
      nonRepeatingLength = s.find('(') - s …

Category: leetcode

Read More

973-K-Closest-Points-To-Origin

Fri 14 November 2025

https://leetcode.com/problems/k-closest-points-to-origin

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]:
    maxHeap = []

    for x, y in points:
      heapq.heappush(maxHeap, (- x * x - y * y, [x, y]))
      if len …

Category: leetcode

Read More
Page 81 of 146

« Prev Next »