Skip to content

Commit 835ea6a

Browse files
add 0456-132-pattern.py
1 parent b5d31a9 commit 835ea6a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-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

0 commit comments

Comments
 (0)