79-Word-Search
https://leetcode.com/problems/word-search
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def exist(self, board: List[List[str]], word: str) -> bool:
m = len(board)
n = len(board[0])
def dfs(i: int, j: int, s: int) -> bool:
if i < 0 …
Read More
790-Domino-And-Tromino-Tiling
https://leetcode.com/problems/domino-and-tromino-tiling
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def numTilings(self, N: int) -> int:
kMod = 1_000_000_007
dp = [0, 1, 2, 5] + [0] * 997
for i in range(4, N + 1):
dp[i] = 2 * dp[i - 1 …
Read More
791-Custom-Sort-String
https://leetcode.com/problems/custom-sort-string
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def customSortString(self, S: str, T: str) -> str:
ans = ""
count = [0] * 26
for c in T:
count[ord(c) - ord('a')] += 1
for c in S:
while count[ord …
Read More
792-Number-Of-Matching-Subsequences
https://leetcode.com/problems/number-of-matching-subsequences
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def numMatchingSubseq(self, s: str, words: List[str]) -> int:
root = {}
def insert(word: str) -> None:
node = root
for c in word:
if c not in node:
node[c] = {'count …
Read More
794-Valid-Tic-Tac-Toe-State
https://leetcode.com/problems/valid-tic-tac-toe-state
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def validTicTacToe(self, board: List[str]) -> bool:
def isWin(c: chr) -> bool:
return any(row.count(c) == 3 for row in board) or \
any(row.count(c) == 3 for …
Read More
795-Number-Of-Subarrays-With-Bounded-Maximum
https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def numSubarrayBoundedMax(self, A: List[int], L: int, R: int) -> int:
ans = 0
l = -1
r = -1
for i, a in enumerate(A):
if a > R:
l = i
if …
Read More
797-All-Paths-From-Source-To-Target
https://leetcode.com/problems/all-paths-from-source-to-target
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
ans = []
def dfs(u: int, path: List[int]) -> None:
if u == len(graph) - 1:
ans.append(path)
return
for …
Read More
8-Panel-1
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct 4 2024, 13:27:36) [GCC 11.2.0]'
!pip show panel | grep "Version:"
import panel as pn
import holoviews as hv
import numpy as np …
Read More
8-String-To-Integer-Atoi
https://leetcode.com/problems/string-to-integer-atoi
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def myAtoi(self, s: str) -> int:
s = s.strip()
if not s:
return 0
sign = -1 if s[0] == '-' else 1
if s[0] in {'-', '+'}:
s = s[1:]
num …
Read More
80-Remove-Duplicates-From-Sorted-Array-Ii
https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
i = 0
for num in nums:
if i < 2 or num != nums[i - 2]:
nums[i] = num
i += 1
return i
Read More