Skip to content

Instantly share code, notes, and snippets.

@Pet3ris
Created May 16, 2011 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pet3ris/975272 to your computer and use it in GitHub Desktop.
Save Pet3ris/975272 to your computer and use it in GitHub Desktop.
Solutions to lightbox entry question
// This one will probably take up linear stack size in most compilers although it shouldn't
f(int n,int*a){return n-1?n-*a+f(n-1,a+1):1;}
// A proper solution
static int find_missing_number(int n, int[] numbers)
{
long sum = (long)n * (n + 1) / 2;
for (int x : numbers)
sum -= x;
return (int)sum;
}
def find_missing_number(n, numbers):
return n * (n + 1) / 2 - sum(numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment