1-Two-Sum

Sat 17 May 2025

https://leetcode.com/problems/two-sum

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def twoSum(self, nums: List[int], target: int) -> List[int]:
    numToIndex = {}

    for i, num in enumerate(nums):
      if target - num in numToIndex:
        return numToIndex[target - num], i
      numToIndex[num] = i
new Solution().twoSum()

Score: 5

Category: leetcode


1-Two-Sums

Sat 17 May 2025
# https://leetcode.com/problems/two-sum
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml311; pyv: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0]'
print(pyu.ps2("haystack-ai ollama-haystack python-dotenv"))
haystack-ai==2.8.0
ollama-haystack is not installed in the current environment.
python-dotenv==0.21 …

Category: leetcode

Read More

10-Regular-Expression-Matching

Sat 17 May 2025

https://leetcode.com/problems/regular-expression-matching

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isMatch(self, s: str, p: str) -> bool:
    m = len(s)
    n = len(p)
    # dp[i][j] := True if s[0..i) matches p[0..j)
    dp = [[False] * (n …

Category: leetcode

Read More

100-Same-Tree

Sat 17 May 2025

https://leetcode.com/problems/same-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
    if not p or not q:
      return p == q
    return p.val == q.val and \
        self.isSameTree(p.left …

Category: leetcode

Read More

1001-Grid-Illumination

Sat 17 May 2025

https://leetcode.com/problems/grid-illumination

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def gridIllumination(self, N: int, lamps: List[List[int]], queries: List[List[int]]) -> List[int]:
    ans = []
    rows = Counter()
    cols = Counter()
    diag1 = Counter()
    diag2 = Counter()
    lampsSet = set()

    for i, j …

Category: leetcode

Read More

1002-Find-Common-Characters

Sat 17 May 2025

https://leetcode.com/problems/find-common-characters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def commonChars(self, A: List[str]) -> List[str]:
    ans = []
    commonCount = [math.inf] * 26

    for a in A:
      count = [0] * 26
      for c in a:
        count[ord(c) - ord('a …

Category: leetcode

Read More

1003-Check-If-Word-Is-Valid-After-Substitutions

Sat 17 May 2025

https://leetcode.com/problems/check-if-word-is-valid-after-substitutions

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isValid(self, s: str) -> bool:
    stack = []

    for c in s:
      if c == 'c':
        if len(stack) < 2 or stack[-2] != 'a' or stack[-1] != 'b':
          return False
        stack …

Category: leetcode

Read More

1006-Clumsy-Factorial

Sat 17 May 2025

https://leetcode.com/problems/clumsy-factorial

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def clumsy(self, N: int) -> int:
    if N == 1:
      return 1
    if N == 2:
      return 2
    if N == 3:
      return 6
    if N == 4:
      return 7
    if N % 4 …

Category: leetcode

Read More

1008-Construct-Binary-Search-Tree-From-Preorder-Traversal

Sat 17 May 2025

https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def bstFromPreorder(self, preorder: List[int]) -> Optional[TreeNode]:
    root = TreeNode(preorder[0])
    stack = [root]

    for i in range(1, len(preorder)):
      parent = stack[-1]
      child = TreeNode(preorder[i])
      # Adjust …

Category: leetcode

Read More

1009-Complement-Of-Base-10-Integer

Sat 17 May 2025

https://leetcode.com/problems/complement-of-base-10-integer

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def bitwiseComplement(self, N: int) -> int:
    mask = 1

    while mask < N:
      mask = (mask << 1) + 1

    return mask ^ N
new Solution().bitwiseComplement()

Score: 5

Category: leetcode

Read More
Page 1 of 77

Next »