770-Basic-Calculator-Iv
https://leetcode.com/problems/basic-calculator-iv
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
771-Jewels-And-Stones
https://leetcode.com/problems/jewels-and-stones
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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
Read More
772-Basic-Calculator-Iii
https://leetcode.com/problems/basic-calculator-iii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
774-Minimize-Max-Distance-To-Gas-Station
https://leetcode.com/problems/minimize-max-distance-to-gas-station
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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 …
Read More
775-Global-And-Local-Inversions
https://leetcode.com/problems/global-and-local-inversions
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
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
Read More
776-Split-Bst
https://leetcode.com/problems/split-bst
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def splitBST(self, root: Optional[TreeNode], target: int) -> List[Optional[TreeNode]]:
if not root:
return None, None
if root.val > target:
left, right = self.splitBST(root.left, target)
root …
Read More
78-Subsets
https://leetcode.com/problems/subsets
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
ans = []
def dfs(s: int, path: List[int]) -> None:
ans.append(path)
for i in range(s, len(nums)):
dfs …
Read More
780-Reaching-Points
https://leetcode.com/problems/reaching-points
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:
while sx < tx and sy < ty:
tx, ty = tx % ty, ty % tx
return sx == tx and sy …
Read More
781-Rabbits-In-Forest
https://leetcode.com/problems/rabbits-in-forest
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def numRabbits(self, answers: List[int]) -> int:
ans = 0
count = Counter()
for answer in answers:
if count[answer] % (answer + 1) == 0:
ans += answer + 1
count[answer] += 1
return ans …
Read More
782-Transform-To-Chessboard
https://leetcode.com/problems/transform-to-chessboard
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def movesToChessboard(self, board: List[List[int]]) -> int:
n = len(board)
if any(board[0][0] ^ board[i][0] ^ board[0][j] ^ board[i][j] for i in range …
Read More