忘记是自然选择,重要的是抽取学习方法
双指针 --判断某一非负整数是否是两数平方和(easy) leecode
输入:5输出:true 5=1^2 + 2^2思路:等于从一个有序数组找两个数平方和为target,注意的是最大值肯定小于Math.sqrt(target)
public boolean judgeSquareSum(int c
) {
if (c
< 0) return false;
int i
= 0, j
= (int)Math
.sqrt(c
);
while (i
<= j
) {
if (i
*i
+ j
*j
== c
) {
return true;
}else if (i
*i
+ j
*j
< c
){
i
++;
}else {
j
--;
}
}
return false;
}
费曼学习法:走一遍早上leetcode自己过一遍 todo