From eb977143d86d9434d4128b503989613e1145888d Mon Sep 17 00:00:00 2001 From: Divyata Pandey <101250441+divyatapandey@users.noreply.github.com> Date: Tue, 31 Oct 2023 19:22:32 +0530 Subject: [PATCH] Update Q7-Valid Parentheses --- Amazon/Q7-Valid Parentheses | 90 +++++++++++-------------------------- 1 file changed, 26 insertions(+), 64 deletions(-) diff --git a/Amazon/Q7-Valid Parentheses b/Amazon/Q7-Valid Parentheses index 8cb325a..1286390 100644 --- a/Amazon/Q7-Valid Parentheses +++ b/Amazon/Q7-Valid Parentheses @@ -26,72 +26,34 @@ SOLUTION : Language - C++ -#include - -using namespace std; - -bool isclose(char c) -{ - return (c == ')' || c == '}' || c == ']'); -} -bool valid_Parenthese(string s) -{ + bool isValid(string s) { stack st; - map m; - m['('] = ')'; - m['{'] = '}'; - m['['] = ']'; - for (auto c : s) - { - if (isclose(c)) - { - if (st.empty()) - return false; - if (m[st.top()] == c) - { - st.pop(); - } - else - { - return false; - } - } - else - { - st.push(c); - } + int i=0; + while(i