Skip to content

Commit ced98a8

Browse files
committed
missing number solved
1 parent be76c84 commit ced98a8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

missing-number/mintheon.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
/**
3+
시간복잡도: O(n)
4+
공간복잡도: O(1)
5+
*/
6+
public int missingNumber(int[] nums) {
7+
int n = nums.length;
8+
int expectedSum = n * (n + 1) / 2;
9+
10+
int arraySum = 0;
11+
for(int i = 0; i < nums.length; i++) {
12+
arraySum += nums[i];
13+
}
14+
15+
return expectedSum - arraySum;
16+
}
17+
}

0 commit comments

Comments
 (0)