随笔分类 -  改造过的二分

当你需要解决的问题的输入是排好序的数组,链表,或是排好序的矩阵,要求咱们寻找某些特定元素。这个时候的不二选择就是二分搜索
旋转数组的最小数字
摘要:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。 class Solution { public: //3 4 5 1 2 int minNumberInRota 阅读全文

posted @ 2020-12-06 21:56 wsw_seu 阅读(72) 评论(0) 推荐(0) 编辑

220. Contains Duplicate III(核心:set数组有序/桶排序)
摘要:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and 阅读全文

posted @ 2020-12-06 11:51 wsw_seu 阅读(85) 评论(0) 推荐(0) 编辑

378. Kth Smallest Element in a Sorted Matrix(大顶堆、小顶堆)
摘要:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is th 阅读全文

posted @ 2020-11-01 17:05 wsw_seu 阅读(92) 评论(0) 推荐(0) 编辑

154. Find Minimum in Rotated Sorted Array II(循环数组查找)
摘要: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]). F 阅读全文

posted @ 2020-09-13 14:01 wsw_seu 阅读(96) 评论(0) 推荐(0) 编辑

局部最小值(二分)
摘要:局部最小存在的几种情况,1. 长度为1,arr[0]就是局部最小;2. 数组的开头,如果arr[0] < arr[1] ,arr[0]被定义为局部最小。 3. 数组的结尾,如果arr[N-1] < arr[N-2] ,arr[N-1]被定义为局部最小。 所以剩下就是数组下标1~N-2之间的了。再按a 阅读全文

posted @ 2020-09-13 12:13 wsw_seu 阅读(1123) 评论(0) 推荐(0) 编辑

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示