Skip to content

Commit c955ca4

Browse files
committed
Missing Number
1 parent bd7cc59 commit c955ca4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

missing-number/forest000014.java

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

0 commit comments

Comments
 (0)