c# - Find first free element -


i looking query return first number not available in list

int[] list = new int[] { 1,4,2,5,6,7 }; 

for above example expect have result 3.

perhaps this:

int result = enumerable.range(1, list.length)                        .where(i => !list.contains(i))                        .firstordefault(); 

this return 0 if list contains integers 1 n.


Comments

Popular posts from this blog

node.js - StackOverflow API not returning JSON -

python - Subclassed QStyledItemDelegate ignores Stylesheet -

php - Laravel 4.1 to Heroku: SQLSTATE[HY000] [2002] No such file or directory -