Check for missing number in sequence

前端 未结 14 1575
太阳男子
太阳男子 2020-12-04 17:58

I have an List which contains 1,2,4,7,9 for example.

I have a range from 0 to 10.

Is there a way to determine what numbers are missin

14条回答
  •  旧时难觅i
    2020-12-04 18:25

    Create an array of num items

    const int numItems = 1000;
    bool found[numItems] = new bool[numItems];
    
    
    List list;
    
    PopulateList(list);
    
    list.ForEach( i => found[i] = true );
    
    // now iterate found for the numbers found
    for(int count = 0; i < numItems; ++numItems){
      Console.WriteList("Item {0} is {1}", count, found[count] ? "there" : "not there");
    }
    

提交回复
热议问题