(int[] nums)
| 2 | |
| 3 | // Dynamic programming, O(n^2) |
| 4 | public int lengthOfLIS(int[] nums) { |
| 5 | if (nums.length == 1) return 1; |
| 6 | |
| 7 | int[] LIS = new int[nums.length]; |
| 8 | Arrays.fill(LIS, 1); |
| 9 | int maximumSoFar = 1; |
| 10 | |
| 11 | for (int i = nums.length - 1; i >= 0; i--) { |
| 12 | for (int j = i + 1; j < nums.length; j++) { |
| 13 | if (nums[i] < nums[j]) { |
| 14 | LIS[i] = Math.max(1 + LIS[j], LIS[i]); |
| 15 | } |
| 16 | } |
| 17 | maximumSoFar = Math.max(maximumSoFar, LIS[i]); |
| 18 | } |
| 19 | return maximumSoFar; |
| 20 | } |
| 21 | |
| 22 | // Binary search, O(nlogn) |
| 23 | public int lengthOfLIS(int[] nums) { |
nothing calls this directly
no test coverage detected