c# - 查找序列中缺失的数字

标签 c# math missing-data

我需要从一系列数字中找到一个缺失的数字

比如

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/

相关文章:

mysql - 无法在 mysql 中正确连接两个表

r - 填充组中的缺失值

c# - 如何测试 wpf gui 线程是否处于事件状态

c# - 在应用程序中使用 jquery 访问所有 td 文本的文本

c# - Monitor.Pulse 和 Monitor.Wait 之间的竞争条件?

c - 当 long-double 计算器失去精度时?

c# - ProtoInclude 属性是什么意思(在 protobuf-net 中)

algorithm - 从给定的数字中,确定三个相近的数字,其乘积是原始数字

python - 确保四舍五入的百分比总和为每组 100(最大余数法)

python - 类型错误 : NAN/INF not supported in write_number() without 'nan_inf_to_errors' Workbook() option