> For the complete documentation index, see [llms.txt](https://shangan.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shangan.gitbook.io/algorithm/he-xin-suan-fa-200-ti/hashmap-and-heap/missing-number.md).

# Missing Number

{% tabs %}
{% tab title="Java" %}

```java
class Solution {
		public int missingNumber(int[] nums) {
		Set<Integer> set = new HashSet<>();
			for (int num : nums) {
				set.add(num);
			}
			for (int i = 0; i < nums.length + 1; i++) {
				if (!set.contains(i)) {
					return i;
				}
			}
			return -1; 
		}
}

```

{% endtab %}
{% endtabs %}
