我需要从一系列数字中找到一个缺失的数字
比如
4 8 12 16 __ 24。
我需要找到丢失的号码。我将如何以编程方式做到这一点?
数字和缺失的展示位置不是静态的,因此它们应该能够改变。
希望这是可能的。
最佳答案
你可以使用一些愚蠢的 linq 就像这个愚蠢的例子:)
var numbers = new List<int>{4, 8, 12, 16, 24, 28, 36};
int first = numbers.First();
int last = numbers.Last();
var missing = Enumerable.Range(first, last).Where(n => n % first == 0).Except(numbers);
Returns:
20
32
-做好迎接反对票的准备-
关于c# - 查找序列中缺失的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17605824/