File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Intuition
2
+ <!-- Describe your first thoughts on how to solve this problem. -->
3
+ λ°°νμ μΈ κ²½μ°μλ§ μ°Έμ μΆλ ₯νλ ` XOR ` μ°μ°μ νμ©νλ€.
4
+ # Approach
5
+ <!-- Describe your approach to solving the problem. -->
6
+ - λ¬Έμ λ₯Ό μΉνν΄λ³΄μ. λͺ¨λ μκ° 2λ²μ© λ±μ₯νκ³ , νλμ μλ§ ν λ² λ±μ₯νλ€κ³ νμ.
7
+ - μ΄ κ²½μ°, λͺ¨λ μλ€μ ` ^ ` μ°μ°μ νλ©΄ ν λ² λ±μ₯ν μλ§μ μ μ μλ€.
8
+ - ` λ°°μ΄μ κΈΈμ΄ ` + ` μΈλ±μ€ ` μ ` ν΄λΉ μΈλ±μ€μΌ λμ μμκ° ` λ€μ λͺ¨λ ` ^ ` μ°μ°νλ©΄
9
+ - λ°°μ΄ + μΈλ±μ€ μνλ‘ λͺ¨λ μλ 1λ²μ© λ±μ₯νλ€.
10
+ - μμκ° μνλ‘ νλμ μλ₯Ό μ μΈνκ³€ 1λ²μ© λ±μ₯νλ€.
11
+ - ν λ²λ§ λ±μ₯ν μκ° missing numberμ΄λ€.
12
+ # Complexity
13
+ - Time complexity: $$ O(n) $$
14
+ <!-- Add your time complexity here, e.g. $$O(n)$$ -->
15
+ : λ°°μ΄μ κΈΈμ΄ ` n ` , μ΄λ₯Ό μννλ€.
16
+ - Space complexity: $$ O(n) $$
17
+
18
+ : inline, μ£Όμ΄μ§ λ°°μ΄μ κΈΈμ΄ ` n `
19
+ <!-- Add your space complexity here, e.g. $$O(n)$$ -->
20
+
21
+ # Code
22
+ ``` go
23
+ func missingNumber (nums []int ) int {
24
+ num := len (nums)
25
+
26
+ for i , n := range nums {
27
+ num ^= i
28
+ num ^= n
29
+ }
30
+ return num
31
+ }
32
+ ```
You canβt perform that action at this time.
0 commit comments