码迷,mamicode.com
首页 > 其他好文 > 详细

怎样查出连续数字中缺失的数字

时间:2019-10-12 20:20:55      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:rgs   tps   csdn   style   http   记录   public   art   做了   

今天遇到一个问题,是要从1-100中找到缺失的数字,而且是杂序排列,开始的时候确实有点懵,怎么弄啊,后来看了别人的idea,自己动手做了一下,在这里做个记录,大家有更好的意见,请回复啊

 

public class PaiXu {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        int a[] = {1, 2, 5, 4, 6, 7, 8, 10};
        int b[] = null;
        b = new int[10];
 
        for (int i = 0; i < a.length; i++) {
            b[a[i] - 1] = 1;
        }
        for(int i = 0; i < b.length; i++) {
            if (b[i] == 0) {
                System.out.println("the lost number is " + (i + 1));
            }
        }
    }

 

参考:怎样查出连续数字中缺失的数字

怎样查出连续数字中缺失的数字

标签:rgs   tps   csdn   style   http   记录   public   art   做了   

原文地址:https://www.cnblogs.com/aspirant/p/11663649.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!