521. Longest Uncommon Subsequence I - LeetCode

Question

521. Longest Uncommon Subsequence I

Solution

题目大意:给两个字符串,找出非共同子串的最大长度

思路:字符串相等就返回-1,不等就返回长度大的那个长度

Java实现:

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());
}

猜你喜欢

转载自www.cnblogs.com/okokabcd/p/9634036.html