Created
May 24, 2013 20:44
-
-
Save bchetty/5646391 to your computer and use it in GitHub Desktop.
Missing Number Problem.
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
public class MissingNumber { | |
public static void main(String[] args) { | |
MissingNumber missingNum = new MissingNumber(); | |
System.out.println("Missing Number : " + missingNum.findMissingNum(new int[] {3,1,2,5,4,7,9,8}, 9)); | |
} | |
private int findMissingNum(int[] intArray, int n) { | |
int res = 0; | |
int sum = 0; | |
for(int i=0;i<intArray.length;i++) { | |
sum += intArray[i]; | |
} | |
return ((n * (n + 1))/2) - sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment