521. Longest Uncommon Subsequence I - LeetCode

Question

521. Longest Uncommon Subsequence Ijava

Solution

題目大意:給兩個字符串,找出非共同子串的最大長度code

思路:字符串相等就返回-1,不等就返回長度大的那個長度ip

Java實現:leetcode

public int findLUSlength(String a, String b) {
    int aLength = a.length();
    int bLength = b.length();
    if (aLength != bLength) return Math.max(aLength, bLength);
    if (a.equals(b)) return -1;
    return aLength;
}

2字符串

public int findLUSlength(String a, String b) {
    if (a.equals(b)) return -1;
    return Math.max(a.length(), b.length());
}
相關文章
相關標籤/搜索