【leetcode】521. Longest Uncommon Subsequence I 最长非共同子序列之一 最长非共同子序列之一

problem

521. Longest Uncommon Subsequence I 

最长非共同子序列之一

题意:

两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个字符串不等,那么较长的那个字符串就是最长非共同子序列。

solution:

class Solution {
public:
    int findLUSlength(string a, string b) {
        if(a==b) return -1;
        return max(a.size(), b.size());
    }
};

or

class Solution {
public:
    int findLUSlength(string a, string b) {
        //if(a==b) return -1;
        return a==b ? -1 : max(a.size(), b.size());
    }
};

参考

1. Leetcode_521. Longest Uncommon Subsequence I;

2. Grandyang_最长非共同子序列之一;

猜你喜欢

转载自www.cnblogs.com/happyamyhope/p/10930310.html