
二分
文章平均质量分 92
小·幸·运
你的所有努力最后都会回赠予你。
展开
-
二分查找-四种题型总结
所谓二分查找,就是从一个查找范围中每次取中间值,然后根据中间值来判断是否满足条件或是缩小查找范围的过程,且这个范围内的值需要是有规律的,比如是有序的。二分查找分很多种情况,有标准二分查找,二分查找左边界,二分查找右边界,二分查找左右边界等。一、标准二分查找:找到target的位置leetcode:35.搜索插入位置给定一个排序数组和一个目标值target,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。你可以假设数组中无重复元素。示例 1:.原创 2021-03-05 19:05:29 · 410 阅读 · 0 评论 -
LeetCode-35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Exam...原创 2018-05-27 22:06:48 · 156 阅读 · 0 评论 -
PAT甲级A1010 Radix (25)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a binary number.Now for any pair of positive in...原创 2018-07-26 21:19:55 · 305 阅读 · 0 评论 -
PAT甲级A1044 Shopping in Mars(25 分)
1044 Shopping in Mars(25 分)Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chai...原创 2018-09-07 22:35:55 · 293 阅读 · 0 评论 -
PAT乙级B1030 完美数列 (25 分)
给定一个正整数数列,和正整数 p,设这个数列中的最大值是 M,最小值是 m,如果 M≤mp,则称这个数列是完美数列。现在给定参数 p 和一些正整数,请你从中选择尽可能多的数构成一个完美数列。输入格式:输入第一行给出两个正整数 N 和 p,其中 N(≤105)是输入的正整数的个数,p(≤109)是给定的参数。第二行给出 N 个正整数,每个数不超过 109。输出格式:...原创 2019-01-27 21:45:03 · 287 阅读 · 0 评论 -
PAT甲级A1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respecti...原创 2019-02-20 21:37:44 · 188 阅读 · 0 评论