From 2e170662f0530f8b3c1e4e37c4b0f58cdd90eba4 Mon Sep 17 00:00:00 2001 From: Emmanuel Valentin Date: Sat, 7 Jun 2025 09:40:06 -0600 Subject: [PATCH 1/4] Add Problem1.py (shortestPalindrome) --- Python/Problem1.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Python/Problem1.py diff --git a/Python/Problem1.py b/Python/Problem1.py new file mode 100644 index 0000000..8ee61e0 --- /dev/null +++ b/Python/Problem1.py @@ -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 + \ No newline at end of file From f92cacefe7db69c91a185d18feca5d601ab301a7 Mon Sep 17 00:00:00 2001 From: Emmanuel Valentin Date: Sat, 7 Jun 2025 10:47:12 -0600 Subject: [PATCH 2/4] Rename Problem1.py to ShortestPalindrome.py --- Python/{Problem1.py => ShortestPalindrome.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Python/{Problem1.py => ShortestPalindrome.py} (100%) diff --git a/Python/Problem1.py b/Python/ShortestPalindrome.py similarity index 100% rename from Python/Problem1.py rename to Python/ShortestPalindrome.py From eaba4824e300b5c1941f9007f896637c985d1936 Mon Sep 17 00:00:00 2001 From: Emmanuel Valentin Date: Sat, 7 Jun 2025 10:48:35 -0600 Subject: [PATCH 3/4] Add PatchingArray.py --- Python/PatchingArray.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Python/PatchingArray.py diff --git a/Python/PatchingArray.py b/Python/PatchingArray.py new file mode 100644 index 0000000..f53bbc1 --- /dev/null +++ b/Python/PatchingArray.py @@ -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 From 68d40bdc9de1928c41846b267c7560fc3d64a70a Mon Sep 17 00:00:00 2001 From: Emmanuel Valentin Date: Sat, 7 Jun 2025 10:51:56 -0600 Subject: [PATCH 4/4] Add BestTimeToBuyAndSellStock.py --- Python/BestTimeToBuyAndSellStock.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Python/BestTimeToBuyAndSellStock.py diff --git a/Python/BestTimeToBuyAndSellStock.py b/Python/BestTimeToBuyAndSellStock.py new file mode 100644 index 0000000..d8ffeda --- /dev/null +++ b/Python/BestTimeToBuyAndSellStock.py @@ -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