|
| 1 | +<h2><a href="https://leetcode.com/problems/132-pattern/">456. 132 Pattern</a></h2><h3>Medium</h3><hr><div><p>Given an array of <code>n</code> integers <code>nums</code>, a <strong>132 pattern</strong> is a subsequence of three integers <code>nums[i]</code>, <code>nums[j]</code> and <code>nums[k]</code> such that <code>i < j < k</code> and <code>nums[i] < nums[k] < nums[j]</code>.</p> |
| 2 | + |
| 3 | +<p>Return <code>true</code><em> if there is a <strong>132 pattern</strong> in </em><code>nums</code><em>, otherwise, return </em><code>false</code><em>.</em></p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong>Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre><strong>Input:</strong> nums = [1,2,3,4] |
| 9 | +<strong>Output:</strong> false |
| 10 | +<strong>Explanation:</strong> There is no 132 pattern in the sequence. |
| 11 | +</pre> |
| 12 | + |
| 13 | +<p><strong>Example 2:</strong></p> |
| 14 | + |
| 15 | +<pre><strong>Input:</strong> nums = [3,1,4,2] |
| 16 | +<strong>Output:</strong> true |
| 17 | +<strong>Explanation:</strong> There is a 132 pattern in the sequence: [1, 4, 2]. |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong>Example 3:</strong></p> |
| 21 | + |
| 22 | +<pre><strong>Input:</strong> nums = [-1,3,2,0] |
| 23 | +<strong>Output:</strong> true |
| 24 | +<strong>Explanation:</strong> There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0]. |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p> </p> |
| 28 | +<p><strong>Constraints:</strong></p> |
| 29 | + |
| 30 | +<ul> |
| 31 | + <li><code>n == nums.length</code></li> |
| 32 | + <li><code>1 <= n <= 2 * 10<sup>5</sup></code></li> |
| 33 | + <li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> |
| 34 | +</ul> |
| 35 | +</div> |
0 commit comments