binary search
feeeeeeet
这个作者很懒,什么都没留下…
展开
-
Leetcode 29. Divide Two Integers
2 solutions- Binary Search & Shifts Solution 1 Binary Search class Solution { public int divide(int dividend, int divisor){ if(dividend==divisor){ return 1; } ...原创 2018-11-17 04:04:12 · 88 阅读 · 0 评论 -
Leetcode 33. Search in Rotated Sorted Array
Divide the array into two parts and at least one of them is sorted. Then decide which part the target belongs to, change the ‘mid’ pointer to new start or end. Slow version class Solution: def sea...原创 2018-12-04 11:31:37 · 80 阅读 · 0 评论 -
Leetcode 34. Find First and Last Position of Element in Sorted Array
Binary Search Similar to Leetcode 33 class Solution: def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ ...原创 2018-12-04 11:34:17 · 58 阅读 · 0 评论 -
Leetcode 35. Search Insert Position
class Solution: def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ start=0 end=len(nums)-1 ...原创 2018-12-04 11:35:47 · 65 阅读 · 0 评论 -
Leetcode 50. Pow(x, n)
class Solution: def myPow(self, x, n): i=abs(n) res = 1.0 while i: if i%2!=0: res = res*x print(res,x) x=x*x ...原创 2018-12-05 23:40:10 · 79 阅读 · 0 评论 -
Leetcode 69. Sqrt(x)
Binary Search and Newton Method Binary Search class Solution: def mySqrt(self, x): """ :type x: int :rtype: int """ l, r = 0, x while l &原创 2018-12-27 06:29:17 · 74 阅读 · 0 评论 -
Leetcode 74. Search a 2D Matrix
Binary Search position 0 1 2 3 4 5 6 7 8 9 10 11 number 1 4 5 8 9 11 12 15 17 18 20 22 row 0 0 0 0 1 1 1 1 2 2 2 2 col 0 1 2 3 0 1 2 3 0 1 2 3 row=position//4 col=position%4原创 2018-12-29 03:11:11 · 84 阅读 · 0 评论