diff --git a/product-of-array-except-self/sonjh1217.swift b/product-of-array-except-self/sonjh1217.swift new file mode 100644 index 000000000..041badf53 --- /dev/null +++ b/product-of-array-except-self/sonjh1217.swift @@ -0,0 +1,24 @@ +class Solution { + func productExceptSelf(_ nums: [Int]) -> [Int] { + var answer = [Int]() + var product:Int = 1 + for i in (0.. 0 { + product *= nums[i-1] + } + answer.append(product) + } + + product = 1 + for i in (1.. Bool { + var count = [Character:Int]() + for char in s { + count[char, default: 0] += 1 + } + + for char in t { + count[char, default: 0] -= 1 + + if count[char]! < 0 { + return false + } + } + + return count.values.allSatisfy {$0 == 0} + + //시간 복잡도 O(n) + //공간 복잡도 O(n) + } +} +