leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 4d3cdfcda8d33bc1cbd5b8f37e755f414e9f522b
parent 9dc1c23a742de973494051e8859e05a3d24e2bc2
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 30 Sep 2023 12:28:27 +0000

Daily Problem

Diffstat:
AProblems/0456.cpp | 17+++++++++++++++++
MREADME.md | 1+
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Problems/0456.cpp b/Problems/0456.cpp @@ -0,0 +1,17 @@ +class Solution { + public: + bool find132pattern(const vector<int> &nums) { + int n3 = INT_MIN; + stack<int> st; + + for (int i = nums.size() - 1; i >= 0; i--) { + if (nums[i] < n3) return true; + while (!st.empty() && st.top() < nums[i]) { + n3 = st.top(); + st.pop(); + } + st.push(nums[i]); + } + return false; + } +}; diff --git a/README.md b/README.md @@ -303,6 +303,7 @@ for solving problems. | 0450 | Medium | [Delete Node in a BST](Problems/0450.cpp) | | 0451 | Medium | [Sort Characters By Frequency](Problems/0451.cpp) | | 0452 | Medium | [Minimum Number of Arrows to Burst Balloons](Problems/0452.cpp) | +| 0456 | Medium | [132 Pattern](Problems/0456.cpp) | | 0459 | Easy | [Repeated Substring Pattern](Problems/0459.cpp) | | 0460 | Hard | [LFU Cache](Problems/0460.cpp) | | 0472 | Hard | [Concatenated Words](Problems/0472.cpp) |