Skip to content

Commit 0d067dd

Browse files
committed
✨ feat: 456. 132 模式;
1 parent e90f903 commit 0d067dd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

456-132-pattern.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
*/
5+
var find132pattern = function(nums) {
6+
const n = nums.length;
7+
if (n < 3) {
8+
return false;
9+
}
10+
11+
let startValue = 0;
12+
let middleValue = 0;
13+
let lastValue = 0;
14+
15+
for ( let j = 1; j < n - 1; j ++) {
16+
const leftNum = nums[j-1];
17+
if ( leftNum < startValue || j == 1 ) {
18+
startValue = leftNum
19+
}
20+
middleValue = nums[j];
21+
if ( startValue >= middleValue ) {
22+
continue;
23+
}
24+
for ( let k = j + 1; k < n; k++ ) {
25+
lastValue = nums[k];
26+
if ( lastValue > startValue && middleValue > lastValue ) {
27+
return true;
28+
}
29+
}
30+
}
31+
return false;
32+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Record LeetCode.
22

3+
[456. 132 模式](./456-132-pattern.js)
34
[1672. 最富有客户的资产总量](./1672-richest-customer-wealth.js)
45
[73. 矩阵置零](./73-set-matrix-zeroes.js)
56
[26. 删除有序数组中的重复项](./26-remove-duplicates-from-sorted-array.js)

0 commit comments

Comments
 (0)