We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2283096 commit f805dc5Copy full SHA for f805dc5
1 file changed
missing-number/juhui-jeong.java
@@ -0,0 +1,31 @@
1
+/*
2
+ * 시간 복잡도: O(n)
3
+ * 공간 복잡도: O(1)
4
+ */
5
+class Solution {
6
+ public int missingNumber(int[] nums) {
7
+ int n = nums.length;
8
+ long expected = n * (n + 1) / 2;
9
+ long actual = 0;
10
+ for (int x : nums) {
11
+ actual += x;
12
+ }
13
+ return (int) (expected - actual);
14
15
+}
16
+
17
18
+ * 시간 복잡도: O(n log n)
19
20
21
22
23
+ Arrays.sort(nums);
24
+ for (int i = 0; i < nums.length; i++) {
25
+ if (i != nums[i]) {
26
+ return i;
27
28
29
+ return nums.length;
30
31
0 commit comments