38-Count-And-Say
https://leetcode.com/problems/count-and-say
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def countAndSay(self, n: int) -> str:
ans = '1'
for _ in range(n - 1):
nxt = ''
i = 0
while i < len(ans):
count = 1
while i + 1 < len(ans) and …
Read More
38-Rate-Of-Change
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
383-Ransom-Note
https://leetcode.com/problems/ransom-note
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
count1 = Counter(ransomNote)
count2 = Counter(magazine)
return all(count1[c] <= count2[c] for c in string.ascii_lowercase)
new Solution().canConstruct()
Score …
Read More
384-Shuffle-An-Array
https://leetcode.com/problems/shuffle-an-array
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def __init__(self, nums: List[int]):
self.nums = nums
def reset(self) -> List[int]:
"""
Resets the array to its original configuration and return it.
"""
return self.nums
def shuffle …
Read More
385-Mini-Parser
https://leetcode.com/problems/mini-parser
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def deserialize(self, s: str) -> NestedInteger:
if s[0] != '[':
return NestedInteger(int(s))
stack = []
for i, c in enumerate(s):
if c == '[':
stack.append(NestedInteger())
start = i + 1
elif …
Read More
387-First-Unique-Character-In-A-String
https://leetcode.com/problems/first-unique-character-in-a-string
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def firstUniqChar(self, s: str) -> int:
count = Counter(s)
for i, c in enumerate(s):
if count[c] == 1:
return i
return -1
new Solution().firstUniqChar()
Score: 5
Read More
389-Find-The-Difference
https://leetcode.com/problems/find-the-difference
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findTheDifference(self, s: str, t: str) -> str:
count = Counter(s)
for i, c in enumerate(t):
count[c] -= 1
if count[c] == -1:
return c
new Solution().findTheDifference …
Read More
39-Combination-Sum
https://leetcode.com/problems/combination-sum
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
ans = []
def dfs(s: int, target: int, path: List[int]) -> None:
if target < 0:
return
if target == 0 …
Read More
39-Connors-Rsi
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
394-Decode-String
https://leetcode.com/problems/decode-string
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def decodeString(self, s: str) -> str:
stack = [] # (prevStr, repeatCount)
currStr = ''
currNum = 0
for c in s:
if c.isdigit():
currNum = currNum * 10 + int(c)
else:
if c == '[':
stack.append …
Read More