随笔分类 - 其它---二分
摘要:题目链接:https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/ 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/search-insert-position/ 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 你可以假设数组中无重复元素。 示例 1: 输入: [1
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/binary-search/ 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。 示例 1: 输入: n
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/ 我们把符合下列属性的数组 A 称作山脉: A.length >= 3存在 0 < i < A.length - 1 使得A[0] < A[1] < ... A[
阅读全文
摘要:#include <iostream> using namespace std; int binSearch(int a[],int b,int n) { int l=0,r=n-1,mid=0; while(l<=r){ mid=(l+r)>>1; if(a[mid]==b) return mid
阅读全文
摘要:Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables
阅读全文
摘要:Recently your team noticed that the computer you use to practice for programming contests is not good enough anymore. Therefore, you decide to buy a n
阅读全文