天天看點

【String-easy】521. Longest Uncommon Subsequence I 最長非公共子串

1. 題目原址

https://leetcode.com/problems/longest-uncommon-subsequence-i/

2. 題目描述

【String-easy】521. Longest Uncommon Subsequence I 最長非公共子串

3. 題目大意

給兩個字元串,最長非公共子序列是指其中一個字元串的子序列而不是另一個字元串的子序列。

4. 解題思路

如果兩個字元相同,就傳回 -1, 如果不相同,則傳回字元串長度大的那個字元串的長度即可

5. AC代碼

class Solution {
    public int findLUSlength(String a, String b) {
         return a.equals(b) ? -1 : Math.max(a.length() , b.length());
    }
}
           

6. 相似題型

【1】 522. Longest Uncommon Subsequence II 題目原址:https://leetcode.com/problems/longest-uncommon-subsequence-ii/