鱼C论坛上Python练习题-72

http://bbs.fishc.com/thread-93788-1-1.html 鱼C论坛上相关Python练习题



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.


  1. minMinMax([-1, 4, 5, -23, 24]); //[-23, -22, 24]
  2. minMinMax([1, 3, -3, -2, 8, -1]); //[-3, 0, 8]
  3. minMinMax([2, -4, 8, -5, 9, 7]); //[-5, -3,9]
复制代码


以下是我写的代码:

# -*- coding: utf-8 -*-
l = [2, -4, 8, -5, 9, 7]
L1 = sorted(l)
L2 = []
L2.append(L1[0])
a = L1[0]
for i in L1:
    if i == a:
        a = a+1
    else:
        L2.append(a)
        break
L2.append(L1[-1])
print L2


运行结果:


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值