439-Ternary-Expression-Parser

Fri 14 November 2025

https://leetcode.com/problems/ternary-expression-parser

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def parseTernary(self, expression: str) -> str:
    c = expression[self.i]

    if self.i + 1 == len(expression) or expression[self.i + 1] == ':':
      self.i += 2
      return str(c)

    self.i …

Category: leetcode

Read More

44-Pivot-Range

Fri 14 November 2025
# Created: 20250104
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'
print(pyu.ps2("yfinance pandas matplotlib"))
yfinance==0.2.51
pandas==2.2.3
matplotlib==3.9.3
import …

Category: stockmarket

Read More

44-Wildcard-Matching

Fri 14 November 2025

https://leetcode.com/problems/wildcard-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

441-Arranging-Coins

Fri 14 November 2025

https://leetcode.com/problems/arranging-coins

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def arrangeCoins(self, n: int) -> int:
    return int((-1 + sqrt(8 * n + 1)) // 2)
new Solution().arrangeCoins()

Score: 5

Category: leetcode

Read More

442-Find-All-Duplicates-In-An-Array

Fri 14 November 2025

https://leetcode.com/problems/find-all-duplicates-in-an-array

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

    for num in nums:
      nums[abs(num) - 1] *= -1
      if nums[abs(num) - 1] > 0:
        ans.append(abs(num))

    return …

Category: leetcode

Read More

443-String-Compression

Fri 14 November 2025

https://leetcode.com/problems/string-compression

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def compress(self, chars: List[str]) -> int:
    ans = 0
    i = 0

    while i < len(chars):
      letter = chars[i]
      count = 0
      while i < len(chars) and chars[i] == letter:
        count …

Category: leetcode

Read More

444-Sequence-Reconstruction

Fri 14 November 2025

https://leetcode.com/problems/sequence-reconstruction

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sequenceReconstruction(self, org: List[int], seqs: List[List[int]]) -> bool:
    if not seqs:
      return False

    n = len(org)
    graph = [[] for _ in range(n)]
    inDegree = [0] * n

    # Build …

Category: leetcode

Read More

445-Add-Two-Numbers-Ii

Fri 14 November 2025

https://leetcode.com/problems/add-two-numbers-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
    stack1 = []
    stack2 = []

    while l1:
      stack1.append(l1)
      l1 = l1.next

    while l2:
      stack2.append(l2)
      l2 = l2.next

    head = None
    carry …

Category: leetcode

Read More

447-Number-Of-Boomerangs

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numberOfBoomerangs(self, points: List[List[int]]) -> int:
    ans = 0

    for x1, y1 in points:
      count = defaultdict(int)
      for x2, y2 in points:
        ans += 2 * count[(x1 - x2)**2 …

Category: leetcode

Read More

448-Find-All-Numbers-Disappeared-In-An-Array

Fri 14 November 2025

https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
    for num in nums:
      index = abs(num) - 1
      nums[index] = -abs(nums[index])

    return [i + 1 for i, num in enumerate …

Category: leetcode

Read More
Page 40 of 146

« Prev Next »