Created
May 16, 2011 20:19
-
-
Save Pet3ris/975272 to your computer and use it in GitHub Desktop.
Solutions to lightbox entry question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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