MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / lengthOfLIS

Method lengthOfLIS

java/0300-longest-increasing-subsequence.java:4–20  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 4

binarySearchMethod · 0.80
sizeMethod · 0.45
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected