809-Expressive-Words

Sat 17 May 2025

https://leetcode.com/problems/expressive-words

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

81-Search-In-Rotated-Sorted-Array-Ii

Sat 17 May 2025

https://leetcode.com/problems/search-in-rotated-sorted-array-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

810-Chalkboard-Xor-Game

Sat 17 May 2025

https://leetcode.com/problems/chalkboard-xor-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def xorGame(self, nums: List[int]) -> bool:
    return functools.reduce(operator.xor, nums) == 0 or len(nums) % 2 == 0
new Solution().xorGame()

Score: 5

Category: leetcode

Read More

811-Subdomain-Visit-Count

Sat 17 May 2025

https://leetcode.com/problems/subdomain-visit-count

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

812-Largest-Triangle-Area

Sat 17 May 2025

https://leetcode.com/problems/largest-triangle-area

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

814-Binary-Tree-Pruning

Sat 17 May 2025

https://leetcode.com/problems/binary-tree-pruning

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

815-Bus-Routes

Sat 17 May 2025

https://leetcode.com/problems/bus-routes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

816-Ambiguous-Coordinates

Sat 17 May 2025

https://leetcode.com/problems/ambiguous-coordinates

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

817-Linked-List-Components

Sat 17 May 2025

https://leetcode.com/problems/linked-list-components

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

819-Most-Common-Word

Sat 17 May 2025

https://leetcode.com/problems/most-common-word

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More
Page 61 of 77

« Prev Next »