src/com/michaelho/DynamicProgramming/DP1.java
/**
         * The method used to find the longest length of subsequence. The runtime is roughly O(N^2).
         *
         * @param strs The first string to be calculated for longest increasing subsequence.
         * @return int The length of LUS.
         * */
The method used to find the longest length of subsequence. The runtime is roughly O(N^2).
@param strs The first string to be calculated for longest increasing subsequence.
@return int The length of LUS.
The method used to find the longest length of subsequence . The runtime is roughly O ( N^2 ) . @param strs The first string to be calculated for longest increasing subsequence . @return int The length of LUS .
int findLUSlength(String[] strs) {
            if (strs.length <= 1) return strs.length;
            List<String> strsList = Arrays.asList(strs);
            strsList.sort(Comparator.comparingInt(String::length).reversed()); 
            for (int i = 0; i < strsList.size(); i++) {
                boolean isLUS = true;
                for (int j = 0; j < strsList.size(); j++) {
                    if (i != j && isSubsequence(strs[i], strs[j])) {
                        isLUS = false;
                        break;
                    }
                }
                if (isLUS) {
                    return strs[i].length();
                }
            }
            return -1;
        }
int findLUSlength ( String [ ] strs ) { if ( strs . length <= 1 ) return strs . length ; List < String > strsList = Arrays . asList ( strs ) ; strsList . sort ( Comparator . comparingInt ( String :: length ) . reversed ( ) ) ; for ( int i = 0 ; i < strsList . size ( ) ; i ++ ) { boolean isLUS = true ; for ( int j = 0 ; j < strsList . size ( ) ; j ++ ) { if ( i != j && isSubsequence ( strs [ i ] , strs [ j ] ) ) { isLUS = false ; break ; } } if ( isLUS ) { return strs [ i ] . length ( ) ; } } return - 1 ; }
The method used to find the longest length of subsequence.
The method used to find the longest length of subsequence .
// Compare by length