Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MissingInt {
- public static void main (String args[]) {
- int[] array = {3,2,1,13,5,6,7,8,9,10,11,12,14};
- // sort the list O(nlogn)
- // or
- // sum the numbers O(n)
- // then subtract the numbers O(n)
- int fullSum = array.length + 1;
- int listSum = 0;
- for (int i=0; i<array.length; i++)
- {
- listSum += array[i];
- fullSum += (i+1);
- }
- System.out.println (fullSum-listSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement