Leetcode

Longest Uncommon Subsequence I

  • Time:O(\max(|\texttt{a}|, |\texttt{b}|))
  • Space:O(1)

C++

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

JAVA

class Solution {
  public int findLUSlength(String a, String b) {
    return a.equals(b) ? -1 : Math.max(a.length(), b.length());
  }
}

Python

class Solution:
  def findLUSlength(self, a: str, b: str) -> int:
    return -1 if a == b else max(len(a), len(b))