Java Solution


  • 1
    R
    public static Boolean check (int c){
            HashSet<Integer> hs = new HashSet<>();
    
            for (int i=0; i<=Math.sqrt(c); i++) {
                hs.add(i * i);
            }
    
            for (int i=0; i<=Math.sqrt(c); i++){
                if (hs.contains(c - (i*i)))
                    return true;
            }
            return false;
        }
    

  • 0

    @Roham said in Java Solution:

    HashSet<Integer> hs = new HashSet<>();

        for (int i=0; i<=Math.sqrt(c); i++) {
            hs.add(i * i);
        }
    
        for (int i=0; i<=Math.sqrt(c); i++){
            if (hs.contains(c - (i*i)))
                return true;
        }
        return false;
    

    why I got a TLE when in contest


  • 0
    R

    @Shadow-Fiend I didn't face TLE problem!


Log in to reply
 

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