diff --git a/Leetcode-Medium/ValidateStackSequences946.cpp b/Leetcode-Medium/ValidateStackSequences946.cpp new file mode 100644 index 0000000..cbaca1c --- /dev/null +++ b/Leetcode-Medium/ValidateStackSequences946.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + bool validateStackSequences(vector& pushed, vector& popped) { + //checking if given arrays are of unequal size + if(pushed.size() != popped.size()){ + return false; + } + stack s; + int i = 0; + for(auto itr : pushed){ + s.push(itr); + while(!s.empty() && s.top() == popped[i]){ + s.pop(); + i++; + } + } + return s.empty(); + } +};