From 49a53605d36b7a95b9eed7e249af5cef11fabbb4 Mon Sep 17 00:00:00 2001 From: ritikakatoch Date: Thu, 13 Oct 2022 16:39:31 +0530 Subject: [PATCH 1/2] Added valid parentheses --- LeeCode_Problems/20.Valid_Parentheses.cpp | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 LeeCode_Problems/20.Valid_Parentheses.cpp diff --git a/LeeCode_Problems/20.Valid_Parentheses.cpp b/LeeCode_Problems/20.Valid_Parentheses.cpp new file mode 100644 index 0000000..6483aa4 --- /dev/null +++ b/LeeCode_Problems/20.Valid_Parentheses.cpp @@ -0,0 +1,49 @@ + +// Time Complexity: O(n); +//Space Complexity: O(n) //auxiliary space +#include +using namespace std; + +class Solution { +public: + bool isValid(string s) { + stack stk; + int i=0; + for(int i=0;i Date: Thu, 13 Oct 2022 16:51:41 +0530 Subject: [PATCH 2/2] Added minimum deletions to make string valid --- ...3.minimumDeletionsToMakeStringBalanced.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LeeCode_Problems/1653.minimumDeletionsToMakeStringBalanced.cpp diff --git a/LeeCode_Problems/1653.minimumDeletionsToMakeStringBalanced.cpp b/LeeCode_Problems/1653.minimumDeletionsToMakeStringBalanced.cpp new file mode 100644 index 0000000..de41373 --- /dev/null +++ b/LeeCode_Problems/1653.minimumDeletionsToMakeStringBalanced.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +class Solution { +public: + int minimumDeletions(string s) { + int bcount=0; + int del=0; + for(int i=0;i0){ + bcount--; + del++; + } + if(s[i]=='b'){ + bcount++; + } + } + return del; + } +}; \ No newline at end of file