From 42849c9e0d8d4f184a5256480a04359cf49f2031 Mon Sep 17 00:00:00 2001 From: rain84 Date: Wed, 9 Oct 2024 16:02:41 +0300 Subject: [PATCH 1/5] feat: add solutions to lc problem: No.0921 --- .../README.md | 32 +++++++++++++++++++ .../README_EN.md | 32 +++++++++++++++++++ .../Solution3.js | 6 ++++ .../Solution3.ts | 6 ++++ 4 files changed, 76 insertions(+) create mode 100644 solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js create mode 100644 solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.ts diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md index fa02a2e88007a..55e9f4e1d5b5f 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md @@ -286,4 +286,36 @@ function minAddToMakeValid(s: string): number { + + +### Solution 3: Replace + recursion + + + +#### TypeScript + +```ts +function minAddToMakeValid(s: string): number { + const l = s.length; + s = s.replace('()', ''); + + return s.length === l ? l : minAddToMakeValid(s); +} +``` + +#### JavaScript + +```js +function minAddToMakeValid(s: string): number { + const l = s.length; + s = s.replace('()', ''); + + return s.length === l ? l : minAddToMakeValid(s); +} +``` + + + + + diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md index ed2031eba82c5..64f773be830a1 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md @@ -284,4 +284,36 @@ function minAddToMakeValid(s: string): number { + + +### Solution 3: Replace + recursion + + + +#### TypeScript + +```ts +function minAddToMakeValid(s: string): number { + const l = s.length; + s = s.replace('()', ''); + + return s.length === l ? l : minAddToMakeValid(s); +} +``` + +#### JavaScript + +```js +function minAddToMakeValid(s: string): number { + const l = s.length; + s = s.replace('()', ''); + + return s.length === l ? l : minAddToMakeValid(s); +} +``` + + + + + diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js new file mode 100644 index 0000000000000..82e35b7c75937 --- /dev/null +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js @@ -0,0 +1,6 @@ +function minAddToMakeValid(s: string): number { + const l = s.length; + s = s.replace('()', ''); + + return s.length === l ? l : minAddToMakeValid(s); +} diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.ts b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.ts new file mode 100644 index 0000000000000..82e35b7c75937 --- /dev/null +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.ts @@ -0,0 +1,6 @@ +function minAddToMakeValid(s: string): number { + const l = s.length; + s = s.replace('()', ''); + + return s.length === l ? l : minAddToMakeValid(s); +} From 1c2274bab91dcffe530ec4c460d1db3ea1894339 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: 2024年10月10日 08:29:12 +0800 Subject: [PATCH 2/5] Update Solution3.js --- .../Solution3.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js index 82e35b7c75937..c9403ec3de6e9 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/Solution3.js @@ -1,6 +1,9 @@ -function minAddToMakeValid(s: string): number { +/** + * @param {string} s + * @return {number} + */ +var minAddToMakeValid = function (s) { const l = s.length; s = s.replace('()', ''); - return s.length === l ? l : minAddToMakeValid(s); -} +}; From 71a9628959951660c39fab58893fe92ecc1de2dd Mon Sep 17 00:00:00 2001 From: Libin YANG Date: 2024年10月10日 08:29:36 +0800 Subject: [PATCH 3/5] Update README_EN.md --- .../README_EN.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md index 64f773be830a1..4710133bd20ad 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README_EN.md @@ -304,12 +304,15 @@ function minAddToMakeValid(s: string): number { #### JavaScript ```js -function minAddToMakeValid(s: string): number { +/** + * @param {string} s + * @return {number} + */ +var minAddToMakeValid = function (s) { const l = s.length; s = s.replace('()', ''); - return s.length === l ? l : minAddToMakeValid(s); -} +}; ``` From 621f15072f9cff251475f2fb916c56890a2a4778 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: 2024年10月10日 08:29:50 +0800 Subject: [PATCH 4/5] Update README.md --- .../0921.Minimum Add to Make Parentheses Valid/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md index 55e9f4e1d5b5f..28eeab639d132 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md @@ -306,12 +306,15 @@ function minAddToMakeValid(s: string): number { #### JavaScript ```js -function minAddToMakeValid(s: string): number { +/** + * @param {string} s + * @return {number} + */ +var minAddToMakeValid = function (s) { const l = s.length; s = s.replace('()', ''); - return s.length === l ? l : minAddToMakeValid(s); -} +}; ``` From 9fd5498d345a139aa7f86d98c8d485fc0420b0df Mon Sep 17 00:00:00 2001 From: Libin YANG Date: 2024年10月10日 08:30:12 +0800 Subject: [PATCH 5/5] Update README.md --- .../0921.Minimum Add to Make Parentheses Valid/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md index 28eeab639d132..0ce6daf0e323b 100644 --- a/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md +++ b/solution/0900-0999/0921.Minimum Add to Make Parentheses Valid/README.md @@ -288,7 +288,7 @@ function minAddToMakeValid(s: string): number { -### Solution 3: Replace + recursion +### 方法三:替换 + 递归

AltStyle によって変換されたページ (->オリジナル) /