
二分
yuccess
这个作者很懒,什么都没留下…
展开
-
29. Divide Two Integers 每一行都是精炼
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 法一:可以直观的利用除数的倍数,但如果这个倍数很大(题目中要求不能用乘法)则会造成LTE, 此法不可行!!! class Solution { public原创 2017-01-06 00:25:14 · 278 阅读 · 0 评论 -
33. Search in Rotated Sorted Array 旋转排序数组极值的二分求法
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If foun原创 2017-01-06 02:56:07 · 396 阅读 · 0 评论 -
34. Search for a Range 史上最简洁的二分搜索的写法
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the原创 2017-01-06 10:22:00 · 539 阅读 · 0 评论 -
35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.原创 2017-01-06 10:50:20 · 229 阅读 · 0 评论 -
50. Pow(x, n) 二分应用的又一经典案例
Implement pow(x, n). 需要注意的两点 1, 当n为 INT_MIN时: int n = INT_MIN; int a = -n; // a == -22147483648 int b = abs(n);// b == -22147483648 2,n 右移了多少次, x 翻多少翻,而不是ans翻多少翻,因为还有ans = ans * x; AC 代码:原创 2017-01-06 23:56:41 · 419 阅读 · 0 评论