Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author John
- *
- */
- public class type {
- public static void main(String[] args) {
- int[] testcase = {3,2,6,4,5};
- int result = findLongestIncreasingSubsequence(testcase);
- System.out.println(result);
- }
- /**
- *
- * @param input
- * @return
- */
- private static int findLongestIncreasingSubsequence(int[] input) {
- // TODO Auto-generated method stub
- int inputLength = input.length;
- int[] longestSubsequence = new int[inputLength];
- for (int i = 0; i < inputLength; i++) {
- longestSubsequence[i] = 1;
- for (int j = 0; j < i; j++) {
- if(input[i] > input[j] && longestSubsequence[i] < longestSubsequence[j])
- longestSubsequence[i] = longestSubsequence[j] + 1;
- }
- }
- int largest = 0;
- for (int i = 0; i < inputLength; i++) {
- if (largest < longestSubsequence[i]) {
- largest = longestSubsequence[i];
- }
- }
- return largest;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement