二分
TIMELIMITE
Time is not enough. I must hurry up !
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode 300 最长递增子序列 动态规划+二分优化
// 经典dp // dp[i]表示以i为结尾的最长公共子序列长度 // dp[i] = max(dp[j]) + 1 if (a[i] > a[j]) // 否则dp[i] = 1 // 优化版在后面 //class Solution { //public: // int lengthOfLIS(vector<int>& nums) { // int n = nums.size(); // vector<int> dp(n + 1.原创 2022-04-10 11:18:02 · 861 阅读 · 0 评论 -
LeetCode 34 二分查找区间
//分别找最左边和最右边 class Solution { public int[] searchRange(int[] nums, int target){ if (nums.length == 0) return new int[]{-1, -1}; int left = searchLeft(nums, target); i...原创 2019-05-03 11:29:52 · 487 阅读 · 0 评论 -
LeetCode 35 搜索插入位置 二分
//二分,刚好上一题有了,这个直接用,改一下判断条件就好了... class Solution { public int searchInsert(int[] nums, int target){ if (nums.length == 0) return 0; int index = searchLeft(nums, target); ...原创 2019-05-05 18:51:40 · 312 阅读 · 0 评论 -
LeetCode 33 搜索旋转排序数组 二分
// 题意要求log(n),毋庸置疑二分查找,直接写二分逻辑没理清楚,所以 // 另辟蹊径. // 由于旋转后一定是前段有序,中间断开,后段有序,并且前段都比后段大 // 则可以通过二分查找先找到前段与后段断开处的下标,再在两端分别进 // 行二分查找即可. // 注意二分的区间,两端的开闭情况,容易死循环 class Solution { public int search(...原创 2019-04-30 16:40:04 · 282 阅读 · 0 评论 -
LeetCode 74 搜索二维矩阵
// 二分,当成一维数组,下标转换 class Solution { public boolean searchMatrix(int[][] matrix, int target) { int n = matrix.length; if (n == 0) return false; int m = matrix[0].length; ...原创 2019-08-25 12:19:54 · 291 阅读 · 0 评论 -
LeetCode 81 搜索旋转排序数组 II
// 找出旋转点,二分 class Solution { public boolean search(int[] nums, int target) { int sep = -1; int n = nums.length; for (int i = 0;i < n - 1; i++){ if (nums[i]...原创 2019-08-25 19:22:50 · 321 阅读 · 0 评论
分享