Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LISLength {
- /**
- * Finds the length of the longest strictly increasing sub-sequence in an array.
- *
- * Time Complexity: O(n^2), where n is the length of the input array.
- *
- * Space Complexity: O(n), where n is the length of the input array.
- *
- *
- * @param nums The input array of integers.
- * @return The length of the longest strictly increasing subsequence.
- */
- private static int findLength(int[] nums) {
- if (nums == null || nums.length == 0) {
- return 0;
- }
- var dp = new int[nums.length];
- var maxLen = 1;
- for (var i = 0; i < nums.length; i++) {
- dp[i] = 1;
- for (var j = 0; j < i; j++) {
- if (nums[i] > nums[j] && dp[i] < dp[j] + 1) {
- dp[i] = dp[j] + 1;
- }
- }
- maxLen = Math.max(maxLen, dp[i]);
- }
- return maxLen;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement