1015-Smallest-Integer-Divisible-By-K
https://leetcode.com/problems/smallest-integer-divisible-by-k
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def smallestRepunitDivByK(self, K: int) -> int:
if K % 10 not in {1, 3, 7, 9}:
return -1
seen = set()
N = 0
for length in range(1, K + 1):
N …
Read More
1016-Binary-String-With-Substrings-Representing-1-To-N
https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def queryString(self, S: str, N: int) -> bool:
if N > 1511:
return False
for i in range(N, N // 2, -1):
if format(i, 'b') not in S:
return …
Read More
1017-Convert-To-Base-2
https://leetcode.com/problems/convert-to-base-2
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def baseNeg2(self, N: int) -> str:
ans = ''
while N:
ans = str(N & 1) + ans
N = -(N >> 1)
return '0' if ans == '' else ans
new Solution().baseNeg2()
Score: 5
Read More
1018-Binary-Prefix-Divisible-By-5
https://leetcode.com/problems/binary-prefix-divisible-by-5
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def prefixesDivBy5(self, A: List[int]) -> List[bool]:
ans = []
num = 0
for a in A:
num = (num * 2 + a) % 5
ans.append(num % 5 == 0)
return ans
Read More
1019-Next-Greater-Node-In-Linked-List
https://leetcode.com/problems/next-greater-node-in-linked-list
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def nextLargerNodes(self, head: ListNode) -> List[int]:
ans = []
stack = []
while head:
while stack and head.val > ans[stack[-1]]:
index = stack.pop()
ans[index] = head.val
stack.append(len …
Read More
102-Binary-Tree-Level-Order-Traversal
https://leetcode.com/problems/binary-tree-level-order-traversal
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
if not root:
return []
ans = []
q = deque([root])
while q:
currLevel = []
for _ in range(len(q)):
node = q.popleft …
Read More
1023-Camelcase-Matching
https://leetcode.com/problems/camelcase-matching
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:
def isMatch(q: str) -> bool:
j = 0
for i, c in enumerate(q):
if j < len(pattern) and c …
Read More
1024-Video-Stitching
https://leetcode.com/problems/video-stitching
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def videoStitching(self, clips: List[List[int]], time: int) -> int:
ans = 0
end = 0
farthest = 0
clips.sort()
i = 0
while farthest < time:
while i < len(clips) and clips …
Read More
1025-Divisor-Game
https://leetcode.com/problems/divisor-game
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def divisorGame(self, N: int) -> bool:
return N % 2 == 0
new Solution().divisorGame()
Score: 5
Read More
1027-Longest-Arithmetic-Subsequence
https://leetcode.com/problems/longest-arithmetic-subsequence
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def longestArithSeqLength(self, nums: List[int]) -> int:
n = len(nums)
ans = 0
# dp[i][k] := length of the longest arithmetic subseq ofnums
# nums[0..i] with k = diff + 500 …
Read More