随笔分类 - Binary Search
摘要:what if the list doesn't contains the result?
阅读全文
摘要:private static String convertBinary(int sum) { StringBuffer binary = new StringBuffer(); while (true) { binary.insert(0, sum % 2); sum = sum / 2...
阅读全文
摘要:这道题是Search in Rotated Sorted Array的扩展,思路在Find Minimum in Rotated Sorted Array中已经介绍过了,和Find Minimum in Rotated Sorted Array唯一的区别是这道题目中元素会有重复的情况出现。不过正是因
阅读全文
摘要:根据题意遍历 但是对于有序的数组还是用二分法效率比较高 这道题是Search in Rotated Sorted Array的扩展,区别就是现在不是找一个目标值了,而是在bst中找最小的元素。主要思路还是跟Search in Rotated Sorted Array差不多,还是通过左边界和中间的大小
阅读全文
摘要:复杂度 时间 O(logN) 空间 O(1) 要求时间复杂度是O(logN) , 只能用二分法了, 其实, 对于排序好的数组多用二分法和双指针.
阅读全文
摘要:We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I'll tell you whether the number is higher o...
阅读全文
摘要:二有序数组常用二分法, 要判断数组是否越界, 而数组的题常用递归, 擦半的方法, 比快排的方法, 少一个partition 遍历, 但是还是分成logn 层, Lintcode: Nuts & Bolts Problem 关键在于找到合适的比较位置, 准备擦出哪个数组的一半, 防止数组越界 The
阅读全文
摘要:有序数组的题, 二分法, 根据mid的位置再确定start 和end的位置, 画图分情况 三种情况 The idea is that when rotating the array, there must be one half of the array that is still in sorte
阅读全文
摘要: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. ...
阅读全文
摘要:while-loop 要非递归写很简单,就用循环, 如果很复杂,就要用递归. but while 容易死循环 看不出就画图 二分法的模板-
阅读全文
摘要:为何不像76. Minimum Window Substring用数组来匹配, 是因为双指针是根据字符串的顺序遍历的, 而数组的话没有顺序.如 For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". 并不是非得ABC的顺序
阅读全文
摘要:https://leetcode.com/problems/minimum-size-subarray-sum/#/solutions Since the given array contains only positive integers, the subarray sum can only i
阅读全文
摘要:https://leetcode.com/problems/valid-perfect-square/#/solutions 数学问题常考虑是否越界, 用long?
阅读全文
摘要:https://leetcode.com/problems/search-a-2d-matrix/#/solutions 考点只有一个:2D array 降维成 1D array 的 index trick.
阅读全文
摘要:https://leetcode.com/submissions/detail/107115768/ http://www.cnblogs.com/EdwardLiu/p/3978972.html 画图分情况讨论: 根据1 增添之 The idea is that when rotating the
阅读全文
摘要:https://leetcode.com/submissions/detail/106777290/ http://www.cnblogs.com/EdwardLiu/p/3981176.html Linkedin: 直接比较就行, 不用compare 或用newton,比较短: 计算x2 = n的
阅读全文
摘要:https://leetcode.com/submissions/detail/106698735/ 要求O(logN)的时间复杂度,想到用二分查找。如果中间元素大于其相邻后续元素,则中间元素左侧(包含该中间元素)必包含一个局部最大值。如果中间元素小于其相邻后续元素,则中间元素右侧必包含一个局部最大
阅读全文
摘要:http://www.cnblogs.com/EdwardLiu/p/6197086.html https://leetcode.com/problems/heaters/#/description Binary Search My solution: Be careful in my binary
阅读全文

浙公网安备 33010602011771号