474-Ones-And-Zeroes
https://leetcode.com/problems/ones-and-zeroes
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findMaxForm(self, strs: List[str], m: int, n: int) -> int:
# dp[i][j] := max size of the subset given i 0's and j 1's are available …
Read More
478-Generate-Random-Point-In-A-Circle
https://leetcode.com/problems/generate-random-point-in-a-circle
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def __init__(self, radius: float, x_center: float, y_center: float):
self.radius = radius
self.x_center = x_center
self.y_center = y_center
def randPoint(self) -> List[float]:
length = sqrt(random.uniform(0, 1 …
Read More
479-Largest-Palindrome-Product
https://leetcode.com/problems/largest-palindrome-product
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def largestPalindrome(self, n: int) -> int:
if n == 1:
return 9
kMod = 1337
upper = pow(10, n) - 1
lower = pow(10, n - 1) - 1
for i in range(upper …
Read More
48-Rotate-Image
https://leetcode.com/problems/rotate-image
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
matrix.reverse()
for i in range(len(matrix)):
for j in range(i + 1, len(matrix)):
matrix[i][j], matrix[j …
Read More
48-Volatality-Stop
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct 4 2024, 13:27:36) [GCC 11.2.0]'
print(pyu.ps2("yfinance pandas matplotlib"))
yfinance==0.2.51
pandas==2.2.3
matplotlib==3.9.3
Read More
483-Smallest-Good-Base
https://leetcode.com/problems/smallest-good-base
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def smallestGoodBase(self, n: str) -> str:
n = int(n)
for m in range(int(math.log(n, 2)), 1, -1):
k = int(n**m**-1)
if (k**(m + 1 …
Read More
484-Find-Permutation
https://leetcode.com/problems/find-permutation
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findPermutation(self, s: str) -> List[int]:
ans = []
stack = []
for i, c in enumerate(s):
stack.append(i + 1)
if c == 'I':
while stack: # Consume all decreasings
ans.append …
Read More
485-Max-Consecutive-Ones
https://leetcode.com/problems/max-consecutive-ones
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
ans = 0
summ = 0
for num in nums:
if num == 0:
summ = 0
else:
summ += num
ans = max(ans, summ)
return ans …
Read More
487-Max-Consecutive-Ones-Ii
https://leetcode.com/problems/max-consecutive-ones-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
ans = 0
zeros = 0
l = 0
for r, num in enumerate(nums):
if num == 0:
zeros += 1
while zeros == 2:
if nums …
Read More
488-Zuma-Game
https://leetcode.com/problems/zuma-game
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findMinStep(self, board: str, hand: str) -> int:
def deDup(board):
start = 0 # Start index of a color sequenece
for i, c in enumerate(board):
if c != board[start …
Read More