19-Remove-Nth-Node-From-End-Of-List

Fri 14 November 2025

https://leetcode.com/problems/remove-nth-node-from-end-of-list

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
    slow = head
    fast = head

    for _ in range(n):
      fast = fast.next
    if not fast:
      return head.next

    while fast.next …

Category: leetcode

Read More

19-Renko-Charts

Fri 14 November 2025
# Created: 20250103
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]'
# !pip install stocktrends
print(pyu.ps2("stocktrends yfinance pandas matplotlib"))
stocktrends==0.1.5
yfinance==0.2.51
pandas …

Category: stockmarket

Read More

190-Reverse-Bits

Fri 14 November 2025

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

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

    for i in range(32):
      if n >> i & 1:
        ans |= 1 << 31 - i

    return ans
new Solution().reverseBits()

Score: 5

Category: leetcode

Read More

191-Number-Of-1-Bits

Fri 14 November 2025

https://leetcode.com/problems/number-of-1-bits

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

    for i in range(32):
      if (n >> i) & 1:
        ans += 1

    return ans
new Solution().hammingWeight()

Score: 5

Category: leetcode

Read More

198-House-Robber

Fri 14 November 2025

https://leetcode.com/problems/house-robber

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def rob(self, nums: List[int]) -> int:
    if not nums:
      return 0
    if len(nums) == 1:
      return nums[0]

    # dp[i]: = max money of robbing nums[0..i]
    dp …

Category: leetcode

Read More

199-Binary-Tree-Right-Side-View

Fri 14 November 2025

https://leetcode.com/problems/binary-tree-right-side-view

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
    if not root:
      return []

    ans = []
    q = deque([root])

    while q:
      size = len(q)
      for i in range(size):
        root = q.popleft …

Category: leetcode

Read More

2-Add-Two-Numbers

Fri 14 November 2025

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

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:
    dummy = ListNode(0)
    curr = dummy
    carry = 0

    while carry or l1 or l2:
      if l1:
        carry += l1.val
        l1 = l1.next …

Category: leetcode

Read More

2-Randomized-Search-1

Fri 14 November 2025

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]'

import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split, RandomizedSearchCV
from sklearn.metrics import accuracy_score
from …

Category: hyperparam-tuning

Read More

2-Seaborn-1

Fri 14 November 2025
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]'

!pip show seaborn | grep "Version:"
Version: 0.13.2
import seaborn as sns
import pandas as pd

data = pd.DataFrame({'x …

Category: plot-compare

Read More

20-Fibonacci-Retracement

Fri 14 November 2025
# Created: 20250103
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
Page 17 of 146

« Prev Next »