Read and think before coding - Clean and clear Java solution

  • 1

    It's always about the interpretation of the problem.

    As long as you realize you can always choose the longer string as the "Subsequence", and surely it cannot be the subsequence of the shorter one, the problem becomes a piece of cake.

    PS: I'm not a big fan of minimizing the lines of code. I think readability is more important :)

    public class Solution {
        public int findLUSlength(String a, String b) {
            int lenA=a.length(), lenB=b.length();
            if(a.equals(b))  return -1;
            else    return Math.max(lenA, lenB);

Log in to reply

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