https://leetcode.com/problems/missing-number/
Given an array containing n distinct numbers taken from0, 1, 2, ..., n, find the one that is missing from the array.For example,
Given nums =[0, 1, 3]return2.Note:
Your algorithm should run in linear runtime complexity.
Solution 1: Binary Search
Time complexity: O(NlogN); Space Complexity O(1)
1 | public class Solution { |
Solution 2: Extra O(N) Space
Time complexity: O(N); Space Complexity O(N)
1 | public class Solution { |
Solution 3: Bit Manipulation
reference: http://believerw.github.io/2016/04/14/Bit-Manipulation/
Time complexity: O(N); Space Complexity O(1)
1 | public class Solution { |
Solution 4: Method Without Bit Manipulation
reference: https://leetcode.com/discuss/96842/1ms-java-solution-without-bit-manipulation
Time complexity: O(N); Space Complexity O(1)
1 | public class Solution { |