21-Merge-Two-Sorted-Lists
https://leetcode.com/problems/merge-two-sorted-lists
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
if not list1 or not list2:
return list1 if list1 else list2
if list1.val > list2.val:
list1 …
Read More
21-Triple-Exponential-Moving-Average
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
210-Course-Schedule-Ii
https://leetcode.com/problems/course-schedule-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from enum import Enum
class State(Enum):
kInit = 0
kVisiting = 1
kVisited = 2
class Solution:
def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:
ans = []
graph = [[] for _ in …
Read More
212-Word-Search-Ii
https://leetcode.com/problems/word-search-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class TrieNode:
def __init__(self):
self.children: Dict[str, TrieNode] = defaultdict(TrieNode)
self.word: Optional[str] = None
class Solution:
def findWords(self, board: List[List[str]], words: List[str]) -> List[str …
Read More
213-House-Robber-Ii
https://leetcode.com/problems/house-robber-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def rob(self, nums: List[int]) -> int:
if not nums:
return 0
if len(nums) < 2:
return nums[0]
def rob(l: int, r: int) -> int:
dp1 = 0
dp2 …
Read More
214-Shortest-Palindrome
https://leetcode.com/problems/shortest-palindrome
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def shortestPalindrome(self, s: str) -> str:
t = s[::-1]
for i in range(len(t)):
if s.startswith(t[i:]):
return t[:i] + s
return t + s
Read More
215-Kth-Largest-Element-In-An-Array
https://leetcode.com/problems/kth-largest-element-in-an-array
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def findKthLargest(self, nums: List[int], k: int) -> int:
minHeap = []
for num in nums:
heapq.heappush(minHeap, num)
if len(minHeap) > k:
heapq.heappop(minHeap)
return minHeap[0]
Read More
216-Combination-Sum-Iii
https://leetcode.com/problems/combination-sum-iii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def combinationSum3(self, k: int, n: int) -> List[List[int]]:
ans = []
def dfs(k: int, n: int, s: int, path: List[int]) -> None:
if k == 0 and n == 0 …
Read More
217-Contains-Duplicate
https://leetcode.com/problems/contains-duplicate
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))
new Solution().containsDuplicate()
Score: 5
Read More
218-The-Skyline-Problem
https://leetcode.com/problems/the-skyline-problem
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:
n = len(buildings)
if n == 0:
return []
if n == 1:
left, right, height = buildings[0]
return [[left, height], [right …
Read More