Java 8 one line solution with Math consideration, O(1) space and O(n) time


  • 0
    A
    import java.util.*;
    public class Solution {
        public int missingNumber(int[] nums) {
            return (((nums.length + 1) * nums.length) / 2 - IntStream.of(nums).sum());
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.