Java Array Compare longestCommonSubsequenceAlternate(int[] input)

Here you can find the source of longestCommonSubsequenceAlternate(int[] input)

Description

longest Common Subsequence Alternate

License

Open Source License

Parameter

Parameter Description
input a parameter

Declaration

public static int longestCommonSubsequenceAlternate(int[] input) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**//  w ww. j  a v  a  2s .c  om
     *
     * @param input
     * @return
     */
    public static int longestCommonSubsequenceAlternate(int[] input) {
        Arrays.sort(input);
        int curCount = 1;
        int maxCount = 0;
        for (int i = 1; i < input.length; i++) {
            if (input[i] - input[i - 1] == 1) {
                curCount++;
            } else {
                curCount = 1;
            }
            if (curCount > maxCount) {
                maxCount = curCount;
            }
        }
        return maxCount;
    }
}

Related

  1. createStainMask(float[] redOD, float[] greenOD, float[] blueOD, double stainThreshold, boolean excludeGray, boolean excludeUncommonColors, boolean[] mask)
  2. getLongestCommonSubsequence(int[] a, int[] b)
  3. getRelativeSegments(String[] targetPath, int commonSegments, int discardedSegments)
  4. longestCommonPrefix(String[] stringArray)
  5. longestCommonSubsequence(E[] s1, E[] s2)
  6. longestCommonSubstring(String s[])