20-Valid-Parentheses

Fri 14 November 2025

https://leetcode.com/problems/valid-parentheses

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 == '(':
        stack.append(')')
      elif c == '{':
        stack.append('}')
      elif c == '[':
        stack.append(']')
      elif not stack or stack.pop …

Category: leetcode

Read More

200-Number-Of-Islands

Fri 14 November 2025

https://leetcode.com/problems/number-of-islands

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numIslands(self, grid: List[List[str]]) -> int:
    m = len(grid)
    n = len(grid[0])
    dirs = [0, 1, 0, -1, 0]

    def bfs(r, c):
      q = deque([(r, c …

Category: leetcode

Read More

201-Bitwise-And-Of-Numbers-Range

Fri 14 November 2025

https://leetcode.com/problems/bitwise-and-of-numbers-range

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def rangeBitwiseAnd(self, m: int, n: int) -> int:
    return self.rangeBitwiseAnd(m >> 1, n >> 1) << 1 if m < n else m
new Solution().rangeBitwiseAnd()

Score: 5

Category: leetcode

Read More

202-Happy-Number

Fri 14 November 2025

https://leetcode.com/problems/happy-number

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isHappy(self, n: int) -> bool:
    def squaredSum(n: int) -> bool:
      summ = 0
      while n:
        summ += pow(n % 10, 2)
        n //= 10
      return summ

    slow = squaredSum(n)
    fast = squaredSum …

Category: leetcode

Read More

203-Remove-Linked-List-Elements

Fri 14 November 2025

https://leetcode.com/problems/remove-linked-list-elements

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def removeElements(self, head: ListNode, val: int) -> ListNode:
    dummy = ListNode(0, head)
    prev = dummy

    while head:
      if head.val != val:
        prev.next = head
        prev = prev.next
      head = head.next …

Category: leetcode

Read More

204-Count-Primes

Fri 14 November 2025

https://leetcode.com/problems/count-primes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def countPrimes(self, n: int) -> int:
    if n <= 2:
      return 0

    isPrime = [False] * 2 + [True] * (n - 2)

    for i in range(2, int(n**0.5) + 1):
      if isPrime …

Category: leetcode

Read More

205-Isomorphic-Strings

Fri 14 November 2025

https://leetcode.com/problems/isomorphic-strings

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isIsomorphic(self, s: str, t: str) -> bool:
    return [*map(s.index, s)] == [*map(t.index, t)]
new Solution().isIsomorphic()

Score: 5

Category: leetcode

Read More

206-Reverse-Linked-List

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
    if not head or not head.next:
      return head

    newHead = self.reverseList(head.next)
    head.next.next = head
    head.next = None …

Category: leetcode

Read More

207-Course-Schedule

Fri 14 November 2025

https://leetcode.com/problems/course-schedule

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
from enum import Enum


class State(Enum):
  kInit = 0
  kVisiting = 1
  kVisited = 2


class Solution:
  def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
    graph = [[] for _ in range(numCourses …

Category: leetcode

Read More

209-Minimum-Size-Subarray-Sum

Fri 14 November 2025

https://leetcode.com/problems/minimum-size-subarray-sum

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minSubArrayLen(self, s: int, nums: List[int]) -> int:
    ans = math.inf
    summ = 0
    j = 0

    for i, num in enumerate(nums):
      summ += num
      while summ >= s:
        ans = min …

Category: leetcode

Read More
Page 18 of 146

« Prev Next »