classSolution { public int lengthOfLIS(int[] nums) { List<Integer> g = new ArrayList<>(); for (int x : nums){ int j = lowerBound(g, x); if(j == g.size()){ g.add(x); } else{ g.set(j, x); } } return g.size(); }
private int lowerBound(List<Integer>g, int target){ int left = -1, right = g.size(); // 开区间 while (left + 1 < right){ int mid = left + (right - left) / 2; if (g.get(mid) < target){ left = mid; } else{ right = mid; } } return right; } }