LeetCode Solutions

521. Longest Uncommon Subsequence I

Time: $O(\max(|\texttt{a}|, |\texttt{b}|))$

Space: $O(1)$

			

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

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

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