From c465c4d6c84951d15ed861b7c150af0e65388fe3 Mon Sep 17 00:00:00 2001 From: Kumar ayush <112839746+A-Y12@users.noreply.github.com> Date: Sat, 25 Feb 2023 23:40:14 +0530 Subject: [PATCH] Valid Parantheses --- Valid Parantheses | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Valid Parantheses diff --git a/Valid Parantheses b/Valid Parantheses new file mode 100644 index 0000000000..6f238f3eea --- /dev/null +++ b/Valid Parantheses @@ -0,0 +1,47 @@ +class Solution { +public: + bool isValid(string s) + { + stack k; + char ch; + for(int i=0;i< s.length();i++) + { + ch=s[i]; + if(ch=='('|| ch=='{'||ch=='[') + { + k.push(ch); + } + else + { + if(!k.empty()) + { + if((ch==')'&& k.top()=='(')|| (ch=='}'&&k.top()=='{')||(ch==']'&&k.top()=='[')) + { + k.pop(); + } + else + { + return false; + } + } + else + { + return false; + } + } + + } + if(k.empty()) + { + return true; + } + else + { + return false; + } + + + + + } +};