274-H-Index

Fri 14 November 2025

https://leetcode.com/problems/h-index

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def hIndex(self, citations: List[int]) -> int:
    n = len(citations)
    accumulate = 0
    count = [0] * (n + 1)

    for citation in citations:
      count[min(citation, n)] += 1

    # To find the largeset …

Category: leetcode

Read More

275-H-Index-Ii

Fri 14 November 2025

https://leetcode.com/problems/h-index-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def hIndex(self, citations: List[int]) -> int:
    l = 0
    r = len(citations)

    while l < r:
      m = (l + r) // 2
      if citations[m] >= len(citations) - m:
        r = m
      else:
        l …

Category: leetcode

Read More

276-Paint-Fence

Fri 14 November 2025

https://leetcode.com/problems/paint-fence

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

    # dp[i] := # Of ways to …

Category: leetcode

Read More

277-Find-The-Celebrity

Fri 14 November 2025

https://leetcode.com/problems/find-the-celebrity

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
# The knows API is already defined for you.
# Returns a bool, whether a knows b
# Def knows(a: int, b: int) -> bool:


class Solution:
  def findCelebrity(self, n: int) -> int:
    candidate …

Category: leetcode

Read More

278-First-Bad-Version

Fri 14 November 2025

https://leetcode.com/problems/first-bad-version

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def firstBadVersion(self, n: int) -> int:
    l = 1
    r = n

    while l < r:
      m = (l + r) >> 1
      if isBadVersion(m):
        r = m
      else:
        l = m + 1

    return l
new …

Category: leetcode

Read More

279-Perfect-Squares

Fri 14 November 2025

https://leetcode.com/problems/perfect-squares

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numSquares(self, n: int) -> int:
    dp = [n] * (n + 1)

    dp[0] = 0
    dp[1] = 1

    for i in range(2, n + 1):
      j = 1
      while j * j <= i …

Category: leetcode

Read More

28-Find-The-Index-Of-The-First-Occurrence-In-A-String

Fri 14 November 2025

https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def strStr(self, haystack: str, needle: str) -> int:
    m = len(haystack)
    n = len(needle)

    for i in range(m - n + 1):
      if haystack[i:i + n] == needle:
        return i …

Category: leetcode

Read More

28-Vortex-Indicator

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

280-Wiggle-Sort

Fri 14 November 2025

https://leetcode.com/problems/wiggle-sort

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def wiggleSort(self, nums: List[int]) -> None:
    # 1. if i is even, then nums[i] <= nums[i - 1]
    # 2. if i is odd, then nums[i] >= nums[i - 1 …

Category: leetcode

Read More

282-Expression-Add-Operators

Fri 14 November 2025

https://leetcode.com/problems/expression-add-operators

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

    # Start index, prev value, current evaluated value
    def dfs(start: int, prev: int, eval: int, path: List[str]) -> None …

Category: leetcode

Read More
Page 26 of 146

« Prev Next »