File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ package leetcode_study
2
+
3
+ /*
4
+ * ์ฃผ์ด์ง ์ซ์ ๋ฐฐ์ด์์ ์กด์ฌํ์ง ์์ ์ ํ๋ณํ๋ ๋ฌธ์
5
+ * 0๋ถํฐ n์ ๋ฒ์์์ ๋ชจ๋ ์๋ ์ ์ผํ๊ฒ ์กด์ฌ
6
+ * ์๊ฐ ๋ณต์ก๋: O(n)
7
+ * -> nums ๋ฐฐ์ด์ ์ํํ๋ฉฐ, ๊ฐ ์์์ ๋ํด board ๋ฐฐ์ด์ ๊ฐ์ ์ค์ : O(n)
8
+ * -> board ๋ฐฐ์ด์ ์ํํ๋ฉฐ, ๊ฐ์ด 0์ธ ์ธ๋ฑ์ค ๊ฒ์: O(n)
9
+ * --> O(n) + O(n) = O(n)
10
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(n)
11
+ * -> ์
๋ ฅ ๋ฐฐ์ด nums์ ํฌ๊ธฐ๊ฐ n์ผ ๋, board ๋ฐฐ์ด์ ํฌ๊ธฐ n + 1: O(n)
12
+ * */
13
+ fun missingNumber (nums : IntArray ): Int {
14
+ val size = nums.size
15
+ val board = IntArray (size+ 1 )
16
+ for (index in nums.indices) {
17
+ board[nums[index]] = 1
18
+ }
19
+
20
+ for (i in board.indices) {
21
+ if (board[i] == 0 ) {
22
+ return i
23
+ }
24
+ }
25
+ return 0
26
+ }
You canโt perform that action at this time.
0 commit comments