
二分Binary Search
不刷脸皮要刷题
这个作者很懒,什么都没留下…
展开
-
sqrt(x)
//二分搜索 //考虑溢出的情况,所以要用long!要通过编译的话,还要强制类型转换回来! public class Solution { public int sqrt(int x) { if (x long beg = 1; long end = x/2; while (beg转载 2014-10-09 12:00:01 · 277 阅读 · 0 评论 -
Search for a range
两次二分 public class Solution { public int[] searchRange(int[] A, int target) { int[] res = new int[2]; res[0] = -1; res[1] = -1; int beg = 0; in转载 2014-10-09 12:14:27 · 316 阅读 · 0 评论