File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 456. 132 Pattern
3
+ * https://leetcode.com/problems/132-pattern/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i],
7
+ * nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].
8
+ *
9
+ * Return true if there is a 132 pattern in nums, otherwise, return false.
10
+ */
11
+
12
+ /**
13
+ * @param {number[] } nums
14
+ * @return {boolean }
15
+ */
16
+ var find132pattern = function ( nums ) {
17
+ const stack = [ ] ;
18
+
19
+ for ( let i = nums . length - 1 , j = - Infinity ; i >= 0 ; i -- ) {
20
+ while ( nums [ i ] > stack [ stack . length - 1 ] ) {
21
+ j = stack . pop ( ) ;
22
+ }
23
+ if ( nums [ i ] < j ) {
24
+ return true ;
25
+ }
26
+ stack . push ( nums [ i ] ) ;
27
+ }
28
+
29
+ return false ;
30
+ } ;
Original file line number Diff line number Diff line change 208
208
448|[ Find All Numbers Disappeared in an Array] ( ./0448-find-all-numbers-disappeared-in-an-array.js ) |Easy|
209
209
451|[ Sort Characters By Frequency] ( ./0451-sort-characters-by-frequency.js ) |Medium|
210
210
452|[ Minimum Number of Arrows to Burst Balloons] ( ./0452-minimum-number-of-arrows-to-burst-balloons.js ) |Medium|
211
+ 456|[ 132 Pattern] ( ./0456-132-pattern.js ) |Medium|
211
212
459|[ Repeated Substring Pattern] ( ./0459-repeated-substring-pattern.js ) |Easy|
212
213
461|[ Hamming Distance] ( ./0461-hamming-distance.js ) |Easy|
213
214
463|[ Island Perimeter] ( ./0463-island-perimeter.js ) |Medium|
You can’t perform that action at this time.
0 commit comments