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());
}
相关文章
相关标签/搜索