702-Search-In-A-Sorted-Array-Of-Unknown-Size

Fri 14 November 2025

https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
# """
# This is ArrayReader's API interface.
# You should not implement it, or speculate about its implementation
# """
# Class ArrayReader:
#   def get(self, index: int) -> int:

class Solution:
  def search(self, reader: 'ArrayReader …

Category: leetcode

Read More

709-To-Lower-Case

Fri 14 November 2025

https://leetcode.com/problems/to-lower-case

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def toLowerCase(self, str: str) -> str:
    return ''.join(chr(ord(c) + 32) if 'A' <= c <= 'Z' else c for c in str)
new Solution().toLowerCase()

Score: 5

Category: leetcode

Read More

71-Simplify-Path

Fri 14 November 2025

https://leetcode.com/problems/simplify-path

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def simplifyPath(self, path: str) -> str:
    stack = []

    for str in path.split('/'):
      if str in ('', '.'):
        continue
      if str == '..':
        if stack:
          stack.pop()
      else:
        stack.append(str)

    return '/' + '/'.join(stack …

Category: leetcode

Read More

710-Random-Pick-With-Blacklist

Fri 14 November 2025

https://leetcode.com/problems/random-pick-with-blacklist

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def __init__(self, N: int, blacklist: List[int]):
    self.validRange = N - len(blacklist)
    self.dict = {}

    for b in blacklist:
      self.dict[b] = -1

    for b in blacklist:
      if b …

Category: leetcode

Read More

711-Number-Of-Distinct-Islands-Ii

Fri 14 November 2025

https://leetcode.com/problems/number-of-distinct-islands-ii

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

    def dfs(i: int, j: int):
      if i < 0 or i == len(grid) or j < 0 or j == len …

Category: leetcode

Read More

713-Subarray-Product-Less-Than-K

Fri 14 November 2025

https://leetcode.com/problems/subarray-product-less-than-k

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
    if k <= 1:
      return 0

    ans = 0
    prod = 1

    j = 0
    for i, num in enumerate(nums):
      prod *= num
      while …

Category: leetcode

Read More

714-Best-Time-To-Buy-And-Sell-Stock-With-Transaction-Fee

Fri 14 November 2025

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxProfit(self, prices: List[int], fee: int) -> int:
    sell = 0
    hold = -math.inf

    for price in prices:
      sell = max(sell, hold + price)
      hold = max(hold, sell - price - fee …

Category: leetcode

Read More

717-1-Bit-And-2-Bit-Characters

Fri 14 November 2025

https://leetcode.com/problems/1-bit-and-2-bit-characters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isOneBitCharacter(self, bits: List[int]) -> bool:
    i = 0
    while i < len(bits) - 1:
      i += bits[i] + 1

    return i == len(bits) - 1
new Solution().isOneBitCharacter()

Score: 5

Category: leetcode

Read More

718-Maximum-Length-Of-Repeated-Subarray

Fri 14 November 2025

https://leetcode.com/problems/maximum-length-of-repeated-subarray

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findLength(self, nums1: List[int], nums2: List[int]) -> int:
    m = len(nums1)
    n = len(nums2)
    ans = 0
    # dp[i][j] := max length of nums1[i:] and nums2[j …

Category: leetcode

Read More

719-Find-K-Th-Smallest-Pair-Distance

Fri 14 November 2025

https://leetcode.com/problems/find-k-th-smallest-pair-distance

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

    l = 0
    r = nums[-1] - nums[0]

    while l < r:
      m = (l + r) // 2
      count = 0

      j = 0 …

Category: leetcode

Read More
Page 60 of 146

« Prev Next »