Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Python/BestTimeToBuyAndSellStock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import math

class Solution:
def maxProfit(self, prices: list[int]) -> int:
sellTwo = 0
holdTwo = -math.inf
sellOne = 0
holdOne = -math.inf

for price in prices:
sellTwo = max(sellTwo, holdTwo + price)
holdTwo = max(holdTwo, sellOne - price)
sellOne = max(sellOne, holdOne + price)
holdOne = max(holdOne , -price)

return sellTwo
14 changes: 14 additions & 0 deletions Python/PatchingArray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def minPatches(self, nums: list[int], n: int) -> int:
patches = 0
min_num = 1
i = 0
while (min_num <= n):
if i < len(nums) and nums[i] <= min_num:
min_num += nums[i]
i += 1
else:
patches += 1
min_num *= 2

return patches
8 changes: 8 additions & 0 deletions Python/ShortestPalindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution:
def shortestPalindrome(self, s: str) -> str:
t = s[::-1]
for i in range(len(s)):
if s.startswith(t[i:]):
return t[:i] + s
return t + s