GO 0ms 2-Pointers Solution


  • 0
    D

    Two pointers solution.

    func judgeSquareSum(c int) bool {
        lo, hi := 0, int(math.Sqrt(float64(c)))
        for t := hi*hi + lo*lo; lo <= hi && t != c; t = hi*hi + lo*lo {
            if t < c {
                lo++
            } else {
                hi--
            }
        }
    
        return c == hi*hi + lo*lo
    }
    

Log in to reply
 

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