809-Expressive-Words
https://leetcode.com/problems/expressive-words
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def expressiveWords(self, S: str, words: List[str]) -> int:
def isStretchy(word: str) -> bool:
n = len(S)
m = len(word)
j = 0
for i in range(n):
if j …
Read More
81-Search-In-Rotated-Sorted-Array-Ii
https://leetcode.com/problems/search-in-rotated-sorted-array-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def search(self, nums: List[int], target: int) -> bool:
l = 0
r = len(nums) - 1
while l <= r:
m = (l + r) // 2
if nums[m] == target:
return True
if …
Read More
810-Chalkboard-Xor-Game
https://leetcode.com/problems/chalkboard-xor-game
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def xorGame(self, nums: List[int]) -> bool:
return functools.reduce(operator.xor, nums) == 0 or len(nums) % 2 == 0
Score: 5
Read More
811-Subdomain-Visit-Count
https://leetcode.com/problems/subdomain-visit-count
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
ans = []
count = Counter()
for cpdomain in cpdomains:
num, domains = cpdomain.split()
num, domains = int(num), domains.split('.')
for i in reversed …
Read More
812-Largest-Triangle-Area
https://leetcode.com/problems/largest-triangle-area
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def largestTriangleArea(self, points: List[List[int]]) -> float:
ans = 0
for Ax, Ay in points:
for Bx, By in points:
for Cx, Cy in points:
ans = max(ans, 0 …
Read More
814-Binary-Tree-Pruning
https://leetcode.com/problems/binary-tree-pruning
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def pruneTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
if not root:
return None
root.left = self.pruneTree(root.left)
root.right = self.pruneTree(root.right)
if not root.left …
Read More
815-Bus-Routes
https://leetcode.com/problems/bus-routes
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def numBusesToDestination(self, routes: List[List[int]], S: int, T: int) -> int:
if S == T:
return 0
graph = defaultdict(list)
usedBuses = set()
for i in range(len(routes)):
for …
Read More
816-Ambiguous-Coordinates
https://leetcode.com/problems/ambiguous-coordinates
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def ambiguousCoordinates(self, S: str) -> List[str]:
def splits(S: str) -> List[str]:
if not S or len(S) > 1 and S[0] == S[-1] == '0':
return []
if S …
Read More
817-Linked-List-Components
https://leetcode.com/problems/linked-list-components
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def numComponents(self, head: ListNode, G: List[int]) -> int:
ans = 0
G = set(G)
while head:
if head.val in G and (head.next == None or head.next.val …
Read More
819-Most-Common-Word
https://leetcode.com/problems/most-common-word
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
banned = set(banned)
words = re.findall(r'\w+', paragraph.lower())
return Counter(word for word in words if word not …
Read More