|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 新手·ing 于 2017-8-6 12:06 编辑
今天给大家带来一道算法题~
Given an unsorted array of integers, find the smallest number in the array, the largest number in the array, and the smallest number between the two array bounds that is not in the array.
For instance, given the array [-1, 4, 5, -23, 24], the smallest number is -23, the largest number is 24, and the smallest number between the array bounds is -22. You may assume the input is well-formed.
You solution should return an array [smallest, minimumAbsent, largest]
The smallest integer should be the integer from the array with the lowest value.
The largest integer should be the integer from the array with the highest value.
The minimumAbsent is the smallest number between the largest and the smallest number that is not in the array.
- minMinMax([-1, 4, 5, -23, 24]); //[-23, -22, 24]
- minMinMax([1, 3, -3, -2, 8, -1]); //[-3, 0, 8]
- minMinMax([2, -4, 8, -5, 9, 7]); //[-5, -3,9]
复制代码
英文看不懂?
回复给你中文版!
为了方便理解,下面是例子:
- minMinMax([-1, 4, 5, -23, 24]); //[-23, -22, 24]
- minMinMax([1, 3, -3, -2, 8, -1]); //[-3, 0, 8]
- minMinMax([2, -4, 8, -5, 9, 7]); //[-5, -3,9]
复制代码
大家一起来啊
解决方案:
|
评分
-
查看全部评分
|