Same idea

public boolean judgeSquareSum(int c) { int n1 = 0, n2 = (int)Math.sqrt(c); while (n1 <= n2) { int cur = n1 * n1 + n2 * n2; if (cur == c) return true; if (cur < c) n1++; else n2--; } return false; }Sum of Square Numbers

Sum of Square Numbers