File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* *
2
+ * ํ์ด
3
+ * - ํน์ ์ ์๊ฐ `nums` ๋ฐฐ์ด์ ํตํด ์ฃผ์ด์ก๋์ง ์ฌ๋ถ๋ฅผ ์ฒดํฌํ๋ ๋ฐฐ์ด `check`๋ฅผ ๋ง๋ญ๋๋ค
4
+ * - `nums`๋ฅผ ์กฐํํ๋ฉฐ `check`๋ฐฐ์ด์ ๊ฐ๋ค์ ๋ณ๊ฒฝํฉ๋๋ค
5
+ * - `check`๋ฐฐ์ด์ ์กฐํํ์ฌ ๋๋ฝ๋์๋ ์ ์๋ฅผ ํ์ธํฉ๋๋ค
6
+ *
7
+ * Big-O
8
+ * - N: ์ฃผ์ด์ง ๋ฐฐ์ด `nums`์ ํฌ๊ธฐ
9
+ *
10
+ * - Time Complexity: O(N)
11
+ * - ๋ฐฐ์ด `nums`๋ฅผ ์กฐํํ๋ ๋ฐ๋ณต๋ฌธ์ O(N)์ ์๊ฐ ๋ณต์ก๋๋ฅผ ๊ฐ์ง๋๋ค
12
+ * - ๋ฐฐ์ด `check`๋ฅผ ์กฐํํ๋ ๋ฐ๋ณต๋ฌธ ๋ํ O(N)์ ์๊ฐ ๋ณต์ก๋๋ฅผ ๊ฐ์ง๋๋ค
13
+ * - ๋ฐ๋ผ์ ์ ์ฒด ์๊ฐ ๋ณต์ก๋๋ O(N)์
๋๋ค
14
+ *
15
+ * - Space Complexity: O(N)
16
+ * - `check`๋ฐฐ์ด์ ํฌ๊ธฐ๊ฐ ์
๋ ฅ๊ฐ์ ๋น๋กํ์ฌ ์ ํ์ ์ผ๋ก ์ฆ๊ฐํฉ๋๋ค
17
+ */
18
+
19
+ class Solution {
20
+ public:
21
+ int missingNumber (vector<int >& nums) {
22
+ int n = nums.size ();
23
+
24
+ vector<bool > check (n + 1 , false );
25
+
26
+ for (auto num : nums) check[num] = true ;
27
+
28
+ int res;
29
+ for (int i = 0 ; i < n + 1 ; i++) {
30
+ if (!check[i]) {
31
+ res = i;
32
+ break ;
33
+ }
34
+ }
35
+
36
+ return res;
37
+ }
38
+ };
You canโt perform that action at this time.
0 commit comments