From ff52ff133c40309ebe439929f67c3b820781ff29 Mon Sep 17 00:00:00 2001 From: jeremyxxxuuu Date: Fri, 10 Mar 2023 14:44:24 +0100 Subject: [PATCH] add 1525 ts solution --- .../1884.ts | 21 +++++++++++++++++++ .../1525.ts | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Problems/28-Egg-Drop-With-2-Eggs-and-N-Floors/1884.ts create mode 100644 Problems/29-Number-of-Good-Ways-to-Split-a-String/1525.ts diff --git a/Problems/28-Egg-Drop-With-2-Eggs-and-N-Floors/1884.ts b/Problems/28-Egg-Drop-With-2-Eggs-and-N-Floors/1884.ts new file mode 100644 index 0000000..c432a4f --- /dev/null +++ b/Problems/28-Egg-Drop-With-2-Eggs-and-N-Floors/1884.ts @@ -0,0 +1,21 @@ +function twoEggDrop(n: number): number { + + let dp : number[][] = Array.from(Array(3), () => new Array(n+1)) + + dp[1][0] = 0; + dp[2][0] = 0; + + for(let i = 1; i <= n; i++) { + dp[1][i] = i; + } + + for(let i = 1; i <= n; i++) { + for(let j = 1; j <= i; j++) { + dp[2][i] = dp[2][i]!==undefined? Math.min(dp[2][i], 1+Math.max(dp[1][j-1],dp[2][i-j])) : 1+Math.max(dp[1][j-1],dp[2][i-j]) + } + } + + return dp[2][n]; + + +}; \ No newline at end of file diff --git a/Problems/29-Number-of-Good-Ways-to-Split-a-String/1525.ts b/Problems/29-Number-of-Good-Ways-to-Split-a-String/1525.ts new file mode 100644 index 0000000..5b03cfc --- /dev/null +++ b/Problems/29-Number-of-Good-Ways-to-Split-a-String/1525.ts @@ -0,0 +1,19 @@ +function numSplits(s: string): number { + const left_set = new Set(); + const right_set = new Set(); + let arr = []; + let res = 0; + + for(let i=0; i=0; i--) { + right_set.add(s[i]); + if(right_set.size === arr[i-1]){ + res++ + } + } + return res; + +}; \ No newline at end of file