Problem statement

https://leetcode.com/problems/longest-uncommon-subsequence-i/

Solution

Just check if words are equal or not. If they are equal, return -1. If they are not, return maximum of their lengths.

Complexity

Time complexity is O(max(m, n)), space complexity is O(1).

Code

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