521. Longest Uncommon Subsequence I

来源:互联网 发布:plsql打开sql文件乱码 编辑:程序博客网 时间:2024/05/17 06:38

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))
0 0
原创粉丝点击