From 95f35f0d2fb29c5aeaecb894a0c79f4d16ee7b77 Mon Sep 17 00:00:00 2001 From: Jai Date: Fri, 14 Oct 2022 09:47:13 +0530 Subject: [PATCH] Create ValidateStackSequences946.cpp --- Leetcode-Medium/ValidateStackSequences946.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Leetcode-Medium/ValidateStackSequences946.cpp 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(); + } +};