From 52b4945432bc093273b8e9270f7b213c7170edba Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Sun, 5 Nov 2023 13:37:57 +0530 Subject: [PATCH 1/3] feat: update README_EN.md to lc problem: No.0020 --- .../0020.Valid Parentheses/README_EN.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/solution/0000-0099/0020.Valid Parentheses/README_EN.md b/solution/0000-0099/0020.Valid Parentheses/README_EN.md index 577d9fa916a5f..440739c3d7fb7 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README_EN.md +++ b/solution/0000-0099/0020.Valid Parentheses/README_EN.md @@ -230,6 +230,27 @@ impl Solution { } ``` +### **C#** + +```C# +public class Solution { + public bool IsValid(string s) { + Stack ch = new Stack(); + foreach (var item in s.ToCharArray()) + if (item == '(') + ch.Push(')'); + else if (item == '[') + ch.Push(']'); + else if (item == '{') + ch.Push('}'); + else if (ch.Count == 0 || ch.Pop() != item) + return false; + + return ch.Count == 0; + } +} +``` + ### **...** ``` From 1141943662ff1c2cf30b653e065a3326e5ef0d27 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Sun, 5 Nov 2023 22:59:11 +0800 Subject: [PATCH 2/3] Update README_EN.md --- .../0020.Valid Parentheses/README_EN.md | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/solution/0000-0099/0020.Valid Parentheses/README_EN.md b/solution/0000-0099/0020.Valid Parentheses/README_EN.md index 440739c3d7fb7..55aed31cf83be 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README_EN.md +++ b/solution/0000-0099/0020.Valid Parentheses/README_EN.md @@ -232,21 +232,22 @@ impl Solution { ### **C#** -```C# +```cs public class Solution { public bool IsValid(string s) { - Stack ch = new Stack(); - foreach (var item in s.ToCharArray()) - if (item == '(') - ch.Push(')'); - else if (item == '[') - ch.Push(']'); - else if (item == '{') - ch.Push('}'); - else if (ch.Count == 0 || ch.Pop() != item) - return false; - - return ch.Count == 0; + Stack stk = new Stack(); + foreach (var c in s.ToCharArray()) { + if (c == '(') { + stk.Push(')'); + } else if (c == '[') { + stk.Push(']'); + } else if (c == '{') { + stk.Push('}'); + } else if (stk.Count == 0 || stk.Pop() != c) { + return false; + } + } + return stk.Count == 0; } } ``` From febd23820af2ab4bff2f12d4ecc8890fd74ccf9b Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Sun, 5 Nov 2023 22:59:40 +0800 Subject: [PATCH 3/3] Update README.md --- .../0020.Valid Parentheses/README.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/solution/0000-0099/0020.Valid Parentheses/README.md b/solution/0000-0099/0020.Valid Parentheses/README.md index de50710ecfec9..90c196ebc2976 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README.md +++ b/solution/0000-0099/0020.Valid Parentheses/README.md @@ -252,6 +252,28 @@ impl Solution { } ``` +### **C#** + +```cs +public class Solution { + public bool IsValid(string s) { + Stack stk = new Stack(); + foreach (var c in s.ToCharArray()) { + if (c == '(') { + stk.Push(')'); + } else if (c == '[') { + stk.Push(']'); + } else if (c == '{') { + stk.Push('}'); + } else if (stk.Count == 0 || stk.Pop() != c) { + return false; + } + } + return stk.Count == 0; + } +} +``` + ### **...** ```