File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
product-of-array-except-self Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func productExceptSelf( _ nums: [ Int ] ) -> [ Int ] {
3
+ var answer = [ Int] ( )
4
+ var product : Int = 1
5
+ for i in ( 0 ..< nums. count) {
6
+ if i > 0 {
7
+ product *= nums [ i- 1 ]
8
+ }
9
+ answer. append ( product)
10
+ }
11
+
12
+ product = 1
13
+ for i in ( 1 ..< nums. count) {
14
+ product *= nums [ nums. count- i]
15
+ answer [ nums. count- 1 - i] *= product
16
+ }
17
+
18
+ return answer
19
+
20
+ //시간 복잡도 O(n)
21
+ //공간 복잡도 O(n)
22
+ }
23
+ }
24
+
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func isAnagram( _ s: String , _ t: String ) -> Bool {
3
+ var count = [ Character: Int] ( )
4
+ for char in s {
5
+ count [ char, default: 0 ] += 1
6
+ }
7
+
8
+ for char in t {
9
+ count [ char, default: 0 ] -= 1
10
+
11
+ if count [ char] ! < 0 {
12
+ return false
13
+ }
14
+ }
15
+
16
+ return count. values. allSatisfy { $0 == 0 }
17
+
18
+ //시간 복잡도 O(n)
19
+ //공간 복잡도 O(n)
20
+ }
21
+ }
22
+
You can’t perform that action at this time.
0 commit comments