From 8415ff6ccaa7b4bc561a099e75f9e3e6856ba116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Mon, 31 Mar 2025 17:20:37 +0900 Subject: [PATCH 1/5] Solution Contains Duplicate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 문제: https://leetcode.com/problems/contains-duplicate/ --- contains-duplicate/doitduri.swift | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 contains-duplicate/doitduri.swift diff --git a/contains-duplicate/doitduri.swift b/contains-duplicate/doitduri.swift new file mode 100644 index 000000000..59691f729 --- /dev/null +++ b/contains-duplicate/doitduri.swift @@ -0,0 +1,6 @@ +class Solution { + func containsDuplicate(_ nums: [Int]) -> Bool { + let numbericSet = Set(nums) + return numbericSet.count < nums.count + } +} From 30f5aae7a09157d228eff5676c90bda46c3e00c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Mon, 31 Mar 2025 18:36:31 +0900 Subject: [PATCH 2/5] Solution Two Sum --- two-sum/doitduri.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 two-sum/doitduri.swift diff --git a/two-sum/doitduri.swift b/two-sum/doitduri.swift new file mode 100644 index 000000000..7ebe1cb5a --- /dev/null +++ b/two-sum/doitduri.swift @@ -0,0 +1,16 @@ +class Solution { + func twoSum(_ nums: [Int], _ target: Int) -> [Int] { + let dict = nums.enumerated().reduce(into: [Int: Int]()) { initialValue, num in + initialValue[num.element] = num.offset + } + + for startIndex in 0.. Date: Mon, 31 Mar 2025 23:43:52 +0900 Subject: [PATCH 3/5] Solution Top K Frequent Elements --- top-k-frequent-elements/doitduri.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 top-k-frequent-elements/doitduri.swift diff --git a/top-k-frequent-elements/doitduri.swift b/top-k-frequent-elements/doitduri.swift new file mode 100644 index 000000000..ec3cc8689 --- /dev/null +++ b/top-k-frequent-elements/doitduri.swift @@ -0,0 +1,18 @@ +class Solution { + func topKFrequent(_ nums: [Int], _ k: Int) -> [Int] { + var tables: [Int: Int] = [:] + + for num in nums { + tables[num] = (tables[num] ?? 0) + 1 + } + + let values = tables.values.sorted().reversed().prefix(k) // k개의 frequent + let result = tables.compactMap { (key: Int, value: Int) -> Int? in + if values.contains(value) { + return key + } + return nil + } + return result + } +} From cdd9f29b066e8bd1f04c109bdb379b748b833d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Tue, 1 Apr 2025 00:11:16 +0900 Subject: [PATCH 4/5] Solution Longest Consecutive Sequence --- longest-consecutive-sequence/doitduri.swift | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 longest-consecutive-sequence/doitduri.swift diff --git a/longest-consecutive-sequence/doitduri.swift b/longest-consecutive-sequence/doitduri.swift new file mode 100644 index 000000000..00df7b0d6 --- /dev/null +++ b/longest-consecutive-sequence/doitduri.swift @@ -0,0 +1,30 @@ +class Solution { + func longestConsecutive(_ nums: [Int]) -> Int { + var result = 1 + var maxResult = 1 + let sortedNums = nums.sorted() + + guard var previous = sortedNums.first else { + return 0 + } + + for index in 1.. Date: Wed, 2 Apr 2025 23:34:07 +0900 Subject: [PATCH 5/5] Solution House Robber --- house-robber/doitduri.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 house-robber/doitduri.swift diff --git a/house-robber/doitduri.swift b/house-robber/doitduri.swift new file mode 100644 index 000000000..1e7d6feec --- /dev/null +++ b/house-robber/doitduri.swift @@ -0,0 +1,23 @@ +class Solution { +func rob(_ nums: [Int]) -> Int { + let length = nums.count + + if length == 1 { + return nums[0] + } + + if length == 2 { + return max(nums[0], nums[1]) + } + + var tables = Array(repeating: 0, count: length) + tables[0] = nums[0] + tables[1] = max(nums[0], nums[1]) + + for i in 2..