https://leetcode-cn.com/problems/increasing-triplet-subsequence/submissions/

    • 跟300题差不多
      1. public boolean increasingTriplet(int[] nums) {
      2. if (nums == null || nums.length < 3) {
      3. return false;
      4. }
      5. int[] ends = new int[3];
      6. ends[0] = nums[0];
      7. int right = 0; // 0..right有效区
      8. int l = 0;
      9. int r = 0;
      10. int m = 0;
      11. for (int i = 1; i < nums.length; i++) {
      12. l = 0;
      13. r = right;
      14. while (l <= r) {
      15. m = (l + r) >> 1;
      16. if (nums[i] > ends[m]) {
      17. l = m + 1;
      18. } else {
      19. r = m - 1;
      20. }
      21. }
      22. right = Math.max(right, l);
      23. if (right > 1) {
      24. return true;
      25. }
      26. ends[l] = nums[i];
      27. }
      28. return false;
      29. }