Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 5. 7. 23:45
https://leetcode.com/problems/132-pattern
132 Pattern - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
이것도 뒤에서 부터 순회하면서 스텍 사용해서 풀면 됨
class Solution:
def find132pattern(self, nums: List[int]) -> bool:
if len(nums)<3:
return False
second_num = -math.inf
stck = []
for i in range(len(nums) - 1, -1, -1):
if nums[i] < second_num:
return True
while stck and stck[-1] < nums[i]:
second_num = stck.pop()
stck.append(nums[i])
return False
반응형