Java Solution


  • 0
    G
    public class Solution {
       public int findLUSlength(String[] strs) {
           int maxLength = -1;
           if(strs == null)
               return -1;
           for(int i=0; i< strs.length; i++){
               boolean isUncommon = true;
               for(int j = 0; j< strs.length; j++){
                   if(i == j)
                       continue;
                   if(isSubSequence(strs[j],strs[i])){
                       isUncommon = false;
                       break;
                   }
               }
               if(isUncommon && strs[i].length() > maxLength){
                   maxLength = strs[i].length();
               }
           }
           return maxLength;
       }
       boolean isSubSequence(String s1, String s2){
           for(int i=0; i< s2.length(); i++){
               int index = s1.indexOf(s2.charAt(i));
               if(index == -1)
                   return false;
               if(index == (s1.length() - 1))
                   s1 = "";
               else
                   s1 = s1.substring(index+1);
           }
           return true;
       }
    }
    

Log in to reply
 

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