Skip to content

Commit 23f1c5f

Browse files
committed
feat: missing-number
1 parent 8d25cb7 commit 23f1c5f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

missing-number/std-freejia.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int missingNumber(int[] nums) {
3+
4+
int totalSum = 0;
5+
// 0부터 nums.length 까지 전부 합
6+
for (int i = 0; i <= nums.length; i++) {
7+
totalSum += i;
8+
}
9+
// 0부터 n까지 전부 합
10+
for (int i = 0; i < nums.length; i++) {
11+
totalSum -= nums[i];
12+
}
13+
14+
return totalSum;
15+
}
16+
}

0 commit comments

Comments
 (0)