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 6a63316 commit 16977f7Copy full SHA for 16977f7
โmissing-number/taekwon-dev.java
@@ -0,0 +1,22 @@
1
+/**
2
+ * ์๊ฐ ๋ณต์ก๋: O(n)
3
+ * - ๊ณต์ฐจ๊ฐ 1์ธ ๋ฑ์ฐจ์์ด, ๋ฑ์ฐจ์์ด์ ํฉ ๊ณต์ ํ์ฉํ์ฌ ๊ธฐ๋ ๊ฐ์ ๊ณ์ฐ -> O(1)
4
+ * - ์ฃผ์ด์ง ๋ฐฐ์ด์ ์ํํ๋ฉด์ ๊ฐ ์์์ ํฉ์ ๊ณ์ฐ -> O(n)
5
+ * - ๊ธฐ๋ ๊ฐ์์ ์ค์ ๊ฐ ์์์ ํฉ์ ๋นผ๋ฉด ์ ๋ต -> O(1)
6
+ *
7
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(1)
8
9
+ */
10
+class Solution {
11
+ public int missingNumber(int[] nums) {
12
+ int len = nums.length;
13
+ int expectedSum = len * (len + 1) / 2;
14
+ int actualSum = 0;
15
+
16
+ for (int num: nums) {
17
+ actualSum += num;
18
+ }
19
20
+ return expectedSum - actualSum;
21
22
+}
0 commit comments