JAVA treeset easy solution


  • 0
    A
            TreeSet ts = new TreeSet();
            for(int i : nums){
                ts.add(i);
            }
           Object[] result = ts.toArray();
           
           for(Object i :result){
               System.out.print(i +" ");
           }
           int s = ts.size();
           if(s > 2){
               return (int)result[result.length - 3];
           }
           else{
               return (int)result[result.length - 1];
           }
        }```

Log in to reply
 

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