From d8599323255a292bca96fc1caebee64f6fa78afe Mon Sep 17 00:00:00 2001 From: jihyun-fastforward <112370606+jihyun-fastforward@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:03:47 +0900 Subject: [PATCH 1/2] valid anagram --- valid-anagram/sonjh1217.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 valid-anagram/sonjh1217.swift diff --git a/valid-anagram/sonjh1217.swift b/valid-anagram/sonjh1217.swift new file mode 100644 index 000000000..e86bc4f44 --- /dev/null +++ b/valid-anagram/sonjh1217.swift @@ -0,0 +1,22 @@ +class Solution { + func isAnagram(_ s: String, _ t: String) -> 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) + } +} + From cef12741d8f0d14754ad1b19655279efd9ae62e8 Mon Sep 17 00:00:00 2001 From: Jihyun Son Date: Fri, 1 Aug 2025 16:58:25 +0900 Subject: [PATCH 2/2] product of array except self --- product-of-array-except-self/sonjh1217.swift | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 product-of-array-except-self/sonjh1217.swift 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..