674-Longest-Continuous-Increasing-Subsequence
https://leetcode.com/problems/longest-continuous-increasing-subsequence
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findLengthOfLCIS(self, nums: List[int]) -> int:
ans = 0
j = 0
for i in range(len(nums)):
if i > 0 and nums[i] <= nums[i - 1]:
j = i
ans …
Read More
678-Valid-Parenthesis-String
https://leetcode.com/problems/valid-parenthesis-string
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def checkValidString(self, s: str) -> bool:
low = 0
high = 0
for c in s:
if c == '(':
low += 1
high += 1
elif c == ')':
if low > 0:
low -= 1
high -= 1 …
Read More
679-24-Game
https://leetcode.com/problems/24-game
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def judgePoint24(self, nums: List[int]) -> bool:
def generate(a: float, b: float) -> List[float]:
return [a * b,
math.inf if b == 0 else a / b,
math.inf if …
Read More
68-Text-Justification
https://leetcode.com/problems/text-justification
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:
ans = []
row = []
rowLetters = 0
for word in words:
if rowLetters + len(word) + len(row) > maxWidth:
for i in range …
Read More
680-Valid-Palindrome-Ii
https://leetcode.com/problems/valid-palindrome-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def validPalindrome(self, s: str) -> bool:
def validPalindrome(l: int, r: int) -> bool:
return all(s[i] == s[r - i + l] for i in range(l, (l + r) // 2 …
Read More
681-Next-Closest-Time
https://leetcode.com/problems/next-closest-time
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def nextClosestTime(self, time: str) -> str:
ans = list(time)
digits = sorted(ans)
def nextClosest(digit: chr, limit: chr) -> chr:
next = bisect_right(digits, digit)
return digits[0] if next == 4 …
Read More
683-K-Empty-Slots
https://leetcode.com/problems/k-empty-slots
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def kEmptySlots(self, bulbs: List[int], k: int) -> int:
n = len(bulbs)
ans = math.inf
# day[i] := the day when bulbs[i] is turned on
day = [0] * n
for …
Read More
684-Redundant-Connection
https://leetcode.com/problems/redundant-connection
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class UnionFind:
def __init__(self, n: int):
self.id = [i for i in range(n + 1)]
def union(self, u: int, v: int) -> bool:
i = self.find(u)
j = self.find …
Read More
685-Redundant-Connection-Ii
https://leetcode.com/problems/redundant-connection-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class UnionFind:
def __init__(self, n: int):
self.id = [i for i in range(n + 1)]
def union(self, u: int, v: int) -> bool:
i = self.find(u)
j = self.find …
Read More
686-Repeated-String-Match
https://leetcode.com/problems/repeated-string-match
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def repeatedStringMatch(self, a: str, b: str) -> int:
n = ceil(len(b) / len(a))
s = a * n
if b in s:
return n
if b in s + a:
return …
Read More