Skip to content

521. Longest Uncommon Subsequence I 👎

  • Time: $O(\max(|\texttt{a}|, |\texttt{b}|))$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  int findLUSlength(string a, string b) {
    return a == b ? -1 : max(a.length(), b.length());
  }
};
1
2
3
4
5
class Solution {
  public int findLUSlength(String a, String b) {
    return a.equals(b) ? -1 : Math.max(a.length(), b.length());
  }
}
1
2
3
class Solution:
  def findLUSlength(self, a: str, b: str) -> int:
    return -1 if a == b else max(len(a), len(b))