34-Find-First-And-Last-Position-Of-Element-In-Sorted-Array

Fri 14 November 2025

https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def searchRange(self, nums: List[int], target: int) -> List[int]:
    l = bisect_left(nums, target)
    if l == len(nums) or nums[l] != target:
      return -1, -1
    r = bisect_right(nums, target …

Category: leetcode

Read More

34-Truth-Strength-Index

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

340-Longest-Substring-With-At-Most-K-Distinct-Characters

Fri 14 November 2025

https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int:
    ans = 0
    distinct = 0
    count = Counter()

    l = 0
    for r, c in enumerate(s):
      count[c] += 1
      if count[c] == 1 …

Category: leetcode

Read More

342-Power-Of-Four

Fri 14 November 2025

https://leetcode.com/problems/power-of-four

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isPowerOfFour(self, n: int) -> bool:
    # Why (4^n - 1) % 3 == 0?
    # (4^n - 1) = (2^n - 1)(2^n + 1) and 2^n - 1, 2^n, 2^n …

Category: leetcode

Read More

343-Integer-Break

Fri 14 November 2025

https://leetcode.com/problems/integer-break

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

    ans = 1

    while n > 4:
      n -= 3
      ans *= 3
    ans *= n

    return ans …

Category: leetcode

Read More

344-Reverse-String

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseString(self, s: List[str]) -> None:
    l = 0
    r = len(s) - 1

    while l < r:
      s[l], s[r] = s[r], s[l]
      l += 1
      r -= 1
new …

Category: leetcode

Read More

345-Reverse-Vowels-Of-A-String

Fri 14 November 2025

https://leetcode.com/problems/reverse-vowels-of-a-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseVowels(self, s: str) -> str:
    charList = list(s)
    vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}
    l = 0
    r = len(s) - 1

    while l < r …

Category: leetcode

Read More

349-Intersection-Of-Two-Arrays

Fri 14 November 2025

https://leetcode.com/problems/intersection-of-two-arrays

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

    for num in nums2:
      if num in nums1:
        ans.append(num)
        nums1.remove(num …

Category: leetcode

Read More

35-Detrended-Price-Oscillator

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

35-Search-Insert-Position

Fri 14 November 2025

https://leetcode.com/problems/search-insert-position

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

    while l < r:
      m = (l + r) // 2
      if nums[m] == target:
        return m
      if nums …

Category: leetcode

Read More
Page 33 of 146

« Prev Next »