521. Longest Uncommon Subsequence I

xiaoxiao2021-02-27  519

For strings A, B, when len(A) > len(B), the longest possible subsequence of either A or B is A, and no subsequence of B can be equal to A. Answer: len(A).

When len(A) == len(B), the only subsequence of B equal to A is B; so as long as A != B, the answer remains len(A).

When A == B, any subsequence of A can be found in B and vice versa, so the answer is -1.

class Solution(object): def findLUSlength(self, a, b): """ :type a: str :type b: str :rtype: int """ if a == b: return -1 else: return max(len(a),len(b))
转载请注明原文地址: https://www.6miu.com/read-982.html

最新回复(0)