LintCode/LeetCode/剑指offer
主要是LintCode/LeetCode/剑指offer笔记
leehour
这个作者很懒,什么都没留下…
展开
-
LintCode 66题:Binary Tree Preorder Traversal
这篇文章讲解的是LintCode第66题:二叉树先序遍历—Binary Tree Preorder Traversal题目描述链接ExampleExample 1:Input:{1,2,3}Output:[1,2,3]Explanation: 1 / \ 2 3it will be serialized {1,2,3}Preorder traversalExam...原创 2020-03-19 16:35:55 · 190 阅读 · 0 评论 -
LintCode 39题:Recover Rotated Sorted Array
这篇文章讲解的是LintCode第39题:Recover Rotated Sorted Array题目描述链接ExampleExample1:[4, 5, 1, 2, 3] -> [1, 2, 3, 4, 5]Example2:[6,8,9,1,2] -> [1,2,6,8,9]首先找到第一个比后面的数大的数的索引。把这个数组中索引的前半部分反转,再把后半部分反转,再全...原创 2020-03-19 16:13:27 · 137 阅读 · 0 评论 -
LintCode 75题:Find Peak Element
这篇文章讲解的是LintCode第75题:Find Peak Element题目描述链接ExampleExample 1: Input: [1, 2, 1, 3, 4, 5, 7, 6] Output: 1 or 6 Explanation: return the index of peek.Example 2: Input: [1,2,3,4,1] Output:...原创 2020-03-19 16:08:21 · 160 阅读 · 0 评论 -
LintCode 61题:Search for a Range
这篇文章讲解的是LintCode第61题:在有序数组中查找target的左右边界—Search for a Range题目描述链接ExampleExample 1:Input:[]9Output:[-1,-1]Example 2:Input:[5, 7, 7, 8, 8, 10]8Output:[3, 4]思路是先找到左边界,在找到右边界:class Sol...原创 2020-03-19 15:42:00 · 117 阅读 · 0 评论 -
LintCode 248题:Count of Smaller Number
这篇文章讲解的是LintCode第248题:Count of Smaller Number题目描述链接ExampleExample 1:Input: array =[1,2,7,8,5] queries =[1,8,5]Output:[0,4,2]Example 2:Input: array =[3,4,5,8] queries =[2,4]Output:[0,1]思路是用...原创 2020-03-19 15:18:52 · 117 阅读 · 0 评论 -
LintCode 60题:Search Insert Position
这篇文章讲解的是LintCode第60题:在有序数组中查找插入位置—Search Insert Position题目描述链接Example[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0也是二分法模板,但是需要找到第一个大于等于target的索引值:class Solution: """...原创 2020-03-13 11:14:58 · 88 阅读 · 0 评论 -
LintCode 28题:Search a 2D Matrix
这篇文章讲解的是LintCode第28题:在二维数组中查找target—Search a 2D Matrix题目描述链接此二维数组的每一行中右侧的数大于左侧的,并且每行第一个元素大于上一行最右侧的元素。ExampleExample 1: Input: [[5]],2 Output: false Explanation: false if not included. Ex...原创 2020-03-13 10:48:44 · 94 阅读 · 0 评论 -
LintCode 14题:First Position of Target
这篇文章讲解的是LintCode第14题:寻找有序数组中第一次出现的目标值—First Position of Target题目描述链接这题只要在二分查找的模板上加以修改即可:class Solution: """ @param nums: The integer array. @param target: Target to find. @return: T...原创 2020-03-12 21:17:44 · 93 阅读 · 0 评论 -
LintCode刷题62:旋转数组查找---Search in Rotated Sorted Array
这篇文章讲解的是LintCode第62题:Search in Rotated Sorted Array题目描述链接DescriptionSuppose a sorted array 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).Yo...原创 2020-02-18 00:10:29 · 127 阅读 · 0 评论 -
LintCode刷题141:求Sqrt(x)
今天的题目是LintCode的第141题:求Sqrt(x)题目描述链接Implement int sqrt(int x).ExampleExample 1: Input: 0 Output: 0Example 2: Input: 3 Output: 1 Explanation: return the largest integer y that y*y <...原创 2020-02-17 23:18:55 · 795 阅读 · 0 评论