日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

132-pattern(蛮难的)

發(fā)布時間:2023/10/11 综合教程 63 老码农
生活随笔 收集整理的這篇文章主要介紹了 132-pattern(蛮难的) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

https://leetcode.com/problems/132-pattern/

下面是我的做法。后來又看了一個提示:

https://discuss.leetcode.com/topic/67881/single-pass-c-o-n-space-and-time-solution-8-lines-with-detailed-explanation

里面的解法非常好。先從后向前找到中間那個數(shù)。利用了棧的特性,非常好。

package com.company;

import java.util.*;

class Solution {
public boolean find132pattern(int[] nums) {
List<Integer> start = new ArrayList();
List<Integer> end = new ArrayList(); int small = Integer.MAX_VALUE;
int big = Integer.MIN_VALUE; for (int i=; i<nums.length; i++) {
if (nums[i] == nums[i-]) {
continue;
}
if (nums[i] > nums[i-]) {
if (nums[i] > big) {
big = nums[i];
}
if (nums[i-] < small) {
small = nums[i-];
}
for (int k=; k<start.size(); k++) {
if (nums[i] > start.get(k) && nums[i] < end.get(k)) {
return true;
}
}
}
else {
if (nums[i] > small) {
return true;
}
for (int k=; k<start.size(); k++) {
if (nums[i] > start.get(k) && nums[i] < end.get(k)) {
return true;
}
}
if (big > Integer.MIN_VALUE) {
start.add(small);
end.add(big);
//System.out.printf("start: %d, end: %d\n", small, big);
small = Integer.MAX_VALUE;
big = Integer.MIN_VALUE;
} }
}
return false;
}
} public class Main { public static void main(String[] args) throws InterruptedException { System.out.println("Hello!");
Solution solution = new Solution(); // Your Codec object will be instantiated and called as such:
int[] g = {, , , , };
boolean ret = solution.find132pattern(g);
System.out.printf("ret:%b\n", ret); System.out.println(); } }

總結(jié)

以上是生活随笔為你收集整理的132-pattern(蛮难的)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。