From 94cce716921d600eb755b0624f36c0bf6b5e4210 Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Tue, 3 Jun 2025 10:09:35 -0600 Subject: [PATCH 1/3] feat: added Shortest Palindrome TS --- Typescript/ShortestPalindrome.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Typescript/ShortestPalindrome.ts diff --git a/Typescript/ShortestPalindrome.ts b/Typescript/ShortestPalindrome.ts new file mode 100644 index 0000000..f76f581 --- /dev/null +++ b/Typescript/ShortestPalindrome.ts @@ -0,0 +1,11 @@ +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; +}; \ No newline at end of file From c301c051e25f1b51f8704e887b5f791df3c5e01c Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Thu, 5 Jun 2025 16:03:11 -0600 Subject: [PATCH 2/3] feat: added Best time to buy and sell stock TS --- Typescript/BestTimeToBuyAndSellStock.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Typescript/BestTimeToBuyAndSellStock.ts diff --git a/Typescript/BestTimeToBuyAndSellStock.ts b/Typescript/BestTimeToBuyAndSellStock.ts new file mode 100644 index 0000000..f0b3bad --- /dev/null +++ b/Typescript/BestTimeToBuyAndSellStock.ts @@ -0,0 +1,16 @@ +function maxProfit(prices: number[]): number { + let sellTwo = 0; + let holdTwo = - Infinity; + let sellOne = 0; + let holdOne = -Infinity; + + for (let i = 0; i < prices.length; i++) { + const price = prices[i]; + + sellTwo = Math.max(sellTwo, holdTwo + price); + holdTwo = Math.max(holdTwo, sellOne - price); + sellOne = Math.max(sellOne, holdOne + price); + holdOne = Math.max(holdOne, -price); + } + return sellTwo; +}; \ No newline at end of file From 175046633da7bc6c89f671babbe44996d0017370 Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Fri, 6 Jun 2025 14:26:35 -0600 Subject: [PATCH 3/3] feat: solved PatchingArray TS --- Typescript/PatchingArray.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Typescript/PatchingArray.ts diff --git a/Typescript/PatchingArray.ts b/Typescript/PatchingArray.ts new file mode 100644 index 0000000..20f5ca5 --- /dev/null +++ b/Typescript/PatchingArray.ts @@ -0,0 +1,16 @@ +function minPatches(nums: number[], n: number): number { + let min_num = 1; + let patches = 0; + let i = 0; + + while (min_num <= n) { + if (i < nums.length && nums[i] <= min_num) { + min_num += nums[i]; + i++; + }else { + patches++; + min_num *= 2; + } + } + return patches; +}; \ No newline at end of file