
查找
文章平均质量分 78
小·幸·运
你的所有努力最后都会回赠予你。
展开
-
二分查找方法总结-蓝红划分法
二分查找,就是从一个查找范围中每次取中间值,然后根据中间值来判断是否满足条件或是缩小查找范围的过程,且这个范围内的值需要是有规律的,比如有序。二分查找分很多种情况,比如[1, 2, 3, 5, 5, 5, 8, 9]:找到第一个 ‘>=5’ 的元素找到最后一个 ‘<5’ 的元素找到第一个 '>5’的元素找到最后一个 ‘<=5’ 的元素以上四种方法的标准模版各不相同很难记忆,下面介绍一种通用记忆方法,蓝红划分法。建模流程:边界条件,以及返回类型如下:方法特性原创 2021-09-13 22:03:54 · 1149 阅读 · 0 评论 -
LeetCode-167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers su...原创 2018-05-28 21:00:07 · 134 阅读 · 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甲级A1022 Digital Library (30)
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number a...原创 2018-08-11 21:25:21 · 154 阅读 · 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甲级A1145 Hashing - Average Search Time(25 分)
1145 Hashing - Average Search Time(25 分)The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys...原创 2018-09-03 22:26:19 · 720 阅读 · 1 评论 -
LeetCode--888. Fair Candy Swap
Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar of candy that Bob has.Since they are friends, they wo...原创 2019-01-13 21:34:14 · 180 阅读 · 1 评论 -
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 评论