Redian新闻
>
黄金可以买了吗?
avatar
黄金可以买了吗?# Stock
z*t
1
如果要求在一个排序的数组里找出一个数字,则可以考虑采用二分查找法。数组可能是
完全排序的,也可能是部分排序,比如前半部分是递增排序,后半部分是递减排序。
先后写了三篇博客讨论这种类型的题目,供参考:
(1) Turning Number in an Array
Turning number is the maximum number in an array which increases and then
decreases. This kind of array is also named unimodal array. Please write a
function which gets the index of the turning number in such an array.
For example, the turning number in array {1, 2, 3, 4, 5, 10, 9, 8, 7, 6} is
10, so its index 5 is the expected output.
http://codercareer.blogspot.com/2011/11/no-22-turning-number-in
(2) Search in a Rotation of an Array
When some elements at the beginning of an array are moved to the end, it
gets a rotation of the original array. Please implement a function to search
a number in a rotation of an increasingly sorted array. Assume there are no
duplicated numbers in the array.
For example, array {3, 4, 5, 1, 2} is a rotation of array {1, 2, 3, 4, 5}.
If the target number to be searched is 4, the index of the number 4 in the
rotation 1 should be returned. If the target number to be searched is 6, -1
should be returned because the number does not exist in the rotated array.
http://codercareer.blogspot.com/2013/03/no-47-search-in-rotatio
(3) Integer Identical to Index
Integers in an array are unique and increasingly sorted. Please write a
function/method to find an integer from the array who equals its index. For
example, in the array {-3, -1, 1, 3, 5}, the number 3 equals its index 3.
http://codercareer.blogspot.com/2014/10/no-57-integer-identical
avatar
P*B
2
盘前跌了些
avatar
c*z
3
thanks!
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。