diff --git a/Team_work_Evan_Jairo/Java/BestTimeToSell.java b/Team_work_Evan_Jairo/Java/BestTimeToSell.java new file mode 100644 index 0000000..242c15b --- /dev/null +++ b/Team_work_Evan_Jairo/Java/BestTimeToSell.java @@ -0,0 +1,48 @@ +class Solution { + public int maxProfit(int[] prices) { + if(prices == null){ + return 0; + } + + int n = prices.length; + int[] der = new int[n]; + int[] izq = new int[n]; + + int precioMin = prices[0]; + int profit = 0; + + for(int i=1;iprices[i]){ + precioMin = prices[i]; + } + + if(izq[i-1] > (prices[i]-precioMin)){ + izq[i] = izq[i-1]; + }else{ + izq[i] = prices[i]-precioMin; + } + } + + + int precioMax = prices[n-1]; + for(int i=n-2;i>=0;i--){ + if(precioMax (precioMax-prices[i])){ + der[i] = der[i+1]; + }else{ + der[i] = precioMax-prices[i]; + } + } + + for(int i=0;i= 0; i--) { + precioMax = Math.max(precioMax, prices[i]); + der[i] = Math.max(der[i + 1], precioMax - prices[i]); + } + + for (let i = 1; i < n; i++) { + profit = Math.max(profit, der[i] + izq[i]); + } + + return profit; +}; diff --git a/Team_work_Evan_Jairo/Typescript/Palindromo.ts b/Team_work_Evan_Jairo/Typescript/Palindromo.ts new file mode 100644 index 0000000..6706fa8 --- /dev/null +++ b/Team_work_Evan_Jairo/Typescript/Palindromo.ts @@ -0,0 +1,25 @@ +function shortestPalindrome(s: string): string { + if (s === "") { + return ""; + } + + const reverse = (str: string): string => str.split("").reverse().join(""); + + if (reverse(s) === s) { + return s; + } + + const n = s.length; + let aux2 = ""; + + for (let i = 1; i < n; i++) { + const aux = s.slice(n - i); + aux2 = reverse(aux) + s; + + if (aux2 === reverse(aux2)) { + break; + } + } + + return aux2; +} diff --git a/Team_work_Evan_Jairo/Typescript/PatchingArray.ts b/Team_work_Evan_Jairo/Typescript/PatchingArray.ts new file mode 100644 index 0000000..c28f8e2 --- /dev/null +++ b/Team_work_Evan_Jairo/Typescript/PatchingArray.ts @@ -0,0 +1,22 @@ +function patchesNeeded(array: number[], n: number): void { + let nextMissing: number = 1; + let index: number = 0; + let patches: number = 0; + + while (nextMissing <= n) { + if (index < array.length && array[index] <= nextMissing) { + nextMissing += array[index]; + index++; + } else { + patches++; + nextMissing += nextMissing; + console.log("nextMissing: " + nextMissing); + } + } + console.log("Patches needed: " + patches); +} + +// Test case +const array: number[] = [1, 3]; +const n: number = 6; +patchesNeeded(array, n); \ No newline at end of file