702-Search-In-A-Sorted-Array-Of-Unknown-Size
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"))
# """
# 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 …
Read More
709-To-Lower-Case
https://leetcode.com/problems/to-lower-case
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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
Read More
71-Simplify-Path
https://leetcode.com/problems/simplify-path
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
710-Random-Pick-With-Blacklist
https://leetcode.com/problems/random-pick-with-blacklist
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
711-Number-Of-Distinct-Islands-Ii
https://leetcode.com/problems/number-of-distinct-islands-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
713-Subarray-Product-Less-Than-K
https://leetcode.com/problems/subarray-product-less-than-k
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
714-Best-Time-To-Buy-And-Sell-Stock-With-Transaction-Fee
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"))
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 …
Read More
717-1-Bit-And-2-Bit-Characters
https://leetcode.com/problems/1-bit-and-2-bit-characters
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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
Read More
718-Maximum-Length-Of-Repeated-Subarray
https://leetcode.com/problems/maximum-length-of-repeated-subarray
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
719-Find-K-Th-Smallest-Pair-Distance
https://leetcode.com/problems/find-k-th-smallest-pair-distance
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More