【Leetcode】521. Longest Uncommon Subsequence I

来源:互联网 发布:矩阵的奇异值是什么 编辑:程序博客网 时间:2024/06/14 20:02

思路:

比较两个字符串的长度,若不相等,则返回长度的较大值,若相等则再判断两个字符串是否相同,若相同则返回-1,否则返回长度。

public class Solution {    public int findLUSlength(String a, String b) {        int lenA = a.length();        int lenB = b.length();        if (lenA != lenB)            return Math.max(lenA, lenB);        else if (!a.equals(b))            return lenA;        else            return -1;    }}

Runtime:3ms

1 0
原创粉丝点击