Skip to content

Commit c3b9658

Browse files
Merge pull request neetcode-gh#2609 from Dhyan-P-Shetty/main
Create: 0456-132-pattern.py, Create: 0946-validate-stack-sequences.py
2 parents 6e1801d + 835ea6a commit c3b9658

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

python/0456-132-pattern.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def find132pattern(self, nums: List[int]) -> bool:
3+
stack = [] # pair [num, curLeftMin], mono-decreasing stack
4+
curMin = nums[0]
5+
6+
for n in nums:
7+
while stack and n >= stack[-1][0]:
8+
stack.pop()
9+
if stack and n < stack[-1][0] and n > stack[-1][1]:
10+
return True
11+
12+
stack.append([n, curMin])
13+
curMin = min(n, curMin)
14+
15+
return False
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def validateStackSequences(self, pushed, popped):
3+
i = 0
4+
stack = []
5+
for n in pushed:
6+
stack.append(n)
7+
while i < len(popped) and stack and popped[i] == stack[-1]:
8+
stack.pop()
9+
i += 1
10+
11+
return not stack
12+
13+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy