题目:
题解:
class Solution:def find132pattern(self, nums: List[int]) -> bool:candidate_i, candidate_j = [-nums[0]], [-nums[0]]for v in nums[1:]:idx_i = bisect.bisect_right(candidate_i, -v)idx_j = bisect.bisect_left(candidate_j, -v)if idx_i < idx_j:return Trueif v < -candidate_i[-1]:candidate_i.append(-v)candidate_j.append(-v)elif v > -candidate_j[-1]:last_i = -candidate_i[-1]while candidate_j and v > -candidate_j[-1]:candidate_i.pop()candidate_j.pop()candidate_i.append(-last_i)candidate_j.append(-v)return False