Java Solution / T : O(N), S : O(1)


  • 0
    J
    public class Solution {
        public int findLUSlength(String a, String b) {
            // If one is substring, longest string
            // If one is not substring, longest string
            // If both are equal, -1
            if(a.equals(b))
                return -1;
            
            return (a.length() > b.length()) ? a.length(): b.length();
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.