From 6cdcf53e41e9c637c0d39dfca729aad3764276fb Mon Sep 17 00:00:00 2001 From: Leonardo Trevizo Date: Tue, 3 Jun 2025 16:33:54 -0600 Subject: [PATCH 1/6] Java folder created java files for the solutions were created and appended into the java folder --- Java/Solution1.java | 4 ++++ Java/Solution2.java | 4 ++++ Java/Solution3.java | 4 ++++ Java/Solution4.java | 24 ++++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 Java/Solution1.java create mode 100644 Java/Solution2.java create mode 100644 Java/Solution3.java create mode 100644 Java/Solution4.java diff --git a/Java/Solution1.java b/Java/Solution1.java new file mode 100644 index 0000000..385a197 --- /dev/null +++ b/Java/Solution1.java @@ -0,0 +1,4 @@ +package Java; + +public class Solution1 { +} diff --git a/Java/Solution2.java b/Java/Solution2.java new file mode 100644 index 0000000..4bd3c35 --- /dev/null +++ b/Java/Solution2.java @@ -0,0 +1,4 @@ +package Java; + +public class Solution2 { +} diff --git a/Java/Solution3.java b/Java/Solution3.java new file mode 100644 index 0000000..81cc4fe --- /dev/null +++ b/Java/Solution3.java @@ -0,0 +1,4 @@ +package Java; + +public class Solution3 { +} diff --git a/Java/Solution4.java b/Java/Solution4.java new file mode 100644 index 0000000..4db9d0f --- /dev/null +++ b/Java/Solution4.java @@ -0,0 +1,24 @@ +package Java; + +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.List; + +public class Solution4 { + public String shortestPalindrome(String s){ + + //function shortestPalindrome(s: string): string { + // const t = s.split('').reverse().join(''); + // + // for (let i = 0; i < t.length; i++) { + // if (s.startsWith(t.slice(i))) { + // return t.slice(0, i) + s; + // } + // } + // + // return t + s; + //}; + //String[] t = s.split(""); + return "hello"; + } +} From a2dbbbd0cb1a082c8f0f3462abbebbe0c9166284 Mon Sep 17 00:00:00 2001 From: Leonardo Trevizo Date: Tue, 3 Jun 2025 16:39:56 -0600 Subject: [PATCH 2/6] Java folder created java files for the solutions were created and appended into the java folder --- Java/Solution1.java | 4 ---- Java/Solution2.java | 4 ---- Java/Solution3.java | 4 ---- Java/SolutionA.java | 4 ++++ Java/SolutionB.java | 4 ++++ Java/{Solution4.java => SolutionD.java} | 6 +----- 6 files changed, 9 insertions(+), 17 deletions(-) delete mode 100644 Java/Solution1.java delete mode 100644 Java/Solution2.java delete mode 100644 Java/Solution3.java create mode 100644 Java/SolutionA.java create mode 100644 Java/SolutionB.java rename Java/{Solution4.java => SolutionD.java} (82%) diff --git a/Java/Solution1.java b/Java/Solution1.java deleted file mode 100644 index 385a197..0000000 --- a/Java/Solution1.java +++ /dev/null @@ -1,4 +0,0 @@ -package Java; - -public class Solution1 { -} diff --git a/Java/Solution2.java b/Java/Solution2.java deleted file mode 100644 index 4bd3c35..0000000 --- a/Java/Solution2.java +++ /dev/null @@ -1,4 +0,0 @@ -package Java; - -public class Solution2 { -} diff --git a/Java/Solution3.java b/Java/Solution3.java deleted file mode 100644 index 81cc4fe..0000000 --- a/Java/Solution3.java +++ /dev/null @@ -1,4 +0,0 @@ -package Java; - -public class Solution3 { -} diff --git a/Java/SolutionA.java b/Java/SolutionA.java new file mode 100644 index 0000000..bb74ad1 --- /dev/null +++ b/Java/SolutionA.java @@ -0,0 +1,4 @@ +package Java; + +public class SolutionA { +} diff --git a/Java/SolutionB.java b/Java/SolutionB.java new file mode 100644 index 0000000..6bbfc97 --- /dev/null +++ b/Java/SolutionB.java @@ -0,0 +1,4 @@ +package Java; + +public class SolutionB { +} diff --git a/Java/Solution4.java b/Java/SolutionD.java similarity index 82% rename from Java/Solution4.java rename to Java/SolutionD.java index 4db9d0f..4037fe4 100644 --- a/Java/Solution4.java +++ b/Java/SolutionD.java @@ -1,10 +1,6 @@ package Java; -import java.lang.reflect.Array; -import java.util.Arrays; -import java.util.List; - -public class Solution4 { +public class SolutionD { public String shortestPalindrome(String s){ //function shortestPalindrome(s: string): string { From 65f33d21992f7be5f24df617e39e1f5fa00a28cf Mon Sep 17 00:00:00 2001 From: Leonardo Trevizo Date: Tue, 3 Jun 2025 17:30:19 -0600 Subject: [PATCH 3/6] //NAN Leetcode problems links commented into the SolutionD.java file --- Java/SolutionD.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Java/SolutionD.java b/Java/SolutionD.java index 4037fe4..7dc7454 100644 --- a/Java/SolutionD.java +++ b/Java/SolutionD.java @@ -11,7 +11,10 @@ public String shortestPalindrome(String s){ // return t.slice(0, i) + s; // } // } - // + //https://leetcode.com/problems/shortest-palindrome/description/ + //https://leetcode.com/problems/patching-array/ + //https://leetcode.com/problems/department-top-three-salaries/description/ + //https://leetcode.com/problems/shortest-palindrome/description/ // return t + s; //}; //String[] t = s.split(""); From 07cb0fb7b879b2d1a983ab9ece296c5dc057a6a6 Mon Sep 17 00:00:00 2001 From: Leonardo Trevizo Date: Wed, 4 Jun 2025 20:42:54 -0600 Subject: [PATCH 4/6] Updated SolutionD.java Uploaded solution created during a teams call --- Java/SolutionD.java | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/Java/SolutionD.java b/Java/SolutionD.java index 7dc7454..8abecfb 100644 --- a/Java/SolutionD.java +++ b/Java/SolutionD.java @@ -1,23 +1,13 @@ -package Java; - public class SolutionD { - public String shortestPalindrome(String s){ + public String shortestPalindrome(String s) { + String t = new StringBuilder(s).reverse().toString(); + + for (int i = 0; i < t.length(); i++) { + if (s.startsWith(t.substring(i))) { + return t.substring(0, i) + s; + } + } - //function shortestPalindrome(s: string): string { - // const t = s.split('').reverse().join(''); - // - // for (let i = 0; i < t.length; i++) { - // if (s.startsWith(t.slice(i))) { - // return t.slice(0, i) + s; - // } - // } - //https://leetcode.com/problems/shortest-palindrome/description/ - //https://leetcode.com/problems/patching-array/ - //https://leetcode.com/problems/department-top-three-salaries/description/ - //https://leetcode.com/problems/shortest-palindrome/description/ - // return t + s; - //}; - //String[] t = s.split(""); - return "hello"; + return t + s; } -} +} \ No newline at end of file From 131e498b224307f6b445ffaead170788bc697f9e Mon Sep 17 00:00:00 2001 From: Leonardo Trevizo Date: Fri, 6 Jun 2025 17:19:20 -0600 Subject: [PATCH 5/6] Uploaded meetings codes Upload the solution for each problem obtained from the video call on Teams. --- Java/SolutionA.java | 37 +++++++++++++++++++++++++++++++++++++ Java/SolutionB.java | 17 +++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/Java/SolutionA.java b/Java/SolutionA.java index bb74ad1..3005497 100644 --- a/Java/SolutionA.java +++ b/Java/SolutionA.java @@ -1,4 +1,41 @@ package Java; public class SolutionA { + // + //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 + // + // + // + // + // + // + //class Solution: + //def maxProfit(self, prices: List[int]) -> int: + // sellTwo = 0 + // holdTwo = math.inf + // sellOne = 0 + // holdOne = math.inf + + // for price in prices: + // sellTwo = min(sellTwo, holdTwo - price) + // holdTwo = min(holdTwo, sellOne + price) + // sellOne = min(sellOne, holdOne - price) + // holdOne = min(holdOne , price) + + // return -sellTwo + + // } diff --git a/Java/SolutionB.java b/Java/SolutionB.java index 6bbfc97..a8d0e29 100644 --- a/Java/SolutionB.java +++ b/Java/SolutionB.java @@ -1,4 +1,21 @@ package Java; public class SolutionB { + // + // 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 b1dce210ea069915adb65f4f9e4058462486ad27 Mon Sep 17 00:00:00 2001 From: Leonardo Trevizo Date: Fri, 6 Jun 2025 18:23:42 -0600 Subject: [PATCH 6/6] Updated SolutionA.java & SolutionB.java Translation from the python solution obtained during the Teams videocalls --- Java/SolutionA.java | 50 +++++++++++++-------------------------------- Java/SolutionB.java | 36 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 54 deletions(-) diff --git a/Java/SolutionA.java b/Java/SolutionA.java index 3005497..41c7548 100644 --- a/Java/SolutionA.java +++ b/Java/SolutionA.java @@ -1,41 +1,19 @@ package Java; public class SolutionA { - // - //class Solution: - //def maxProfit(self, prices: List[int]) -> int: - // sellTwo = 0 - // holdTwo = -math.inf - // sellOne = 0 - // holdOne = -math.inf + public int maxProfit(int[] prices) { + int finalSell = 0; + int finalBuy = Integer.MIN_VALUE; + int firstSell = 0; + int firstBuy = Integer.MIN_VALUE; - // for price in prices: - // sellTwo = max(sellTwo, holdTwo + price) - // holdTwo = max(holdTwo, sellOne - price) - // sellOne = max(sellOne, holdOne + price) - // holdOne = max(holdOne , -price) + for (int quote : prices) { + finalSell = Math.max(finalSell, finalBuy + quote); + finalBuy = Math.max(finalBuy, firstSell - quote); + firstSell = Math.max(firstSell, firstBuy + quote); + firstBuy = Math.max(firstBuy, -quote); + } - // return sellTwo - // - // - // - // - // - // - //class Solution: - //def maxProfit(self, prices: List[int]) -> int: - // sellTwo = 0 - // holdTwo = math.inf - // sellOne = 0 - // holdOne = math.inf - - // for price in prices: - // sellTwo = min(sellTwo, holdTwo - price) - // holdTwo = min(holdTwo, sellOne + price) - // sellOne = min(sellOne, holdOne - price) - // holdOne = min(holdOne , price) - - // return -sellTwo - - // -} + return finalSell; + } +} \ No newline at end of file diff --git a/Java/SolutionB.java b/Java/SolutionB.java index a8d0e29..e687f7e 100644 --- a/Java/SolutionB.java +++ b/Java/SolutionB.java @@ -1,21 +1,21 @@ package Java; public class SolutionB { - // - // 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 - // - // -} + public int minPatches(int[] nums, int n) { + int patches = 0; + long smallestUncovered = 1; + int cursor = 0; + + while (smallestUncovered <= n) { + if (cursor < nums.length && nums[cursor] <= smallestUncovered) { + smallestUncovered += nums[cursor]; + cursor++; + } else { + patches++; + smallestUncovered *= 2; + } + } + + return patches; + } +} \ No newline at end of file