Skip to content

Commit 3c8f1c8

Browse files
committed
feat: missing-number
1 parent 5f53f02 commit 3c8f1c8

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

missing-number/minji-go.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
/*
2-
Problem: https://leetcode.com/problems/missing-number/
3-
Description: return the only number in the range that is missing from the array.
4-
Concept: Array, Hash Table, Math, Binary Search, Bit Manipulation, Sorting
5-
Time Complexity: O(N), Runtime 0ms
6-
Space Complexity: O(1), Memory 45.71MB
7-
*/
1+
/**
2+
* <a href="https://leetcode.com/problems/missing-number/">week11-1. missing-number</a>
3+
* <li>Description: Return the only number in the range that is missing from the array</li>
4+
* <li>Topics: Array, Hash Table, Math, Binary Search, Bit Manipulation, Sorting </li>
5+
* <li>Time Complexity: O(N), Runtime 0ms </li>
6+
* <li>Space Complexity: O(1), Memory 45.67MB </li>
7+
*/
88
class Solution {
99
public int missingNumber(int[] nums) {
10-
int n = nums.length;
11-
int missing = n;
12-
13-
for(int i=0; i<n; i++){
14-
missing ^= i;
15-
missing ^= nums[i];
10+
int sum = (nums.length) * (nums.length + 1) / 2;
11+
for (int i = 0; i < nums.length; i++) {
12+
sum -= nums[i];
1613
}
17-
return missing;
14+
return sum;
1815
}
1916
}

0 commit comments

Comments
 (0)