|
@@ -3,6 +3,25 @@ func find132pattern(nums []int) bool {
|
|
|
if n < 3 {
|
|
|
return false
|
|
|
}
|
|
|
- one, three, two := 0, 1, 2
|
|
|
- for one <
|
|
|
+ one, three, two := 0, -1, 0
|
|
|
+ for {
|
|
|
+ for one = three + 1; one < n-1 && nums[one+1] <= nums[one]; one++ {
|
|
|
+ }
|
|
|
+ if n-2 <= one {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for three = one; three < n-1 && nums[three] <= nums[three+1]; three++ {
|
|
|
+ }
|
|
|
+ if n-1 <= three {
|
|
|
+ break
|
|
|
+ } else if three == one {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for two = three + 1; two < n; two++ {
|
|
|
+ if nums[one] < nums[two] && nums[two] < nums[three] {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|