From 50ea04cfa0bcaf6b94e73cfbe06bf9309d47e0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Sat, 12 Apr 2025 17:29:10 +0900 Subject: [PATCH 1/6] Solution Climbing Stairs --- climbing-stairs/doitduri.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 climbing-stairs/doitduri.swift diff --git a/climbing-stairs/doitduri.swift b/climbing-stairs/doitduri.swift new file mode 100644 index 000000000..0a6bfc65a --- /dev/null +++ b/climbing-stairs/doitduri.swift @@ -0,0 +1,11 @@ +class Solution { + func climbStairs(_ n: Int) -> Int { + var tables = [0, 1, 2] + for i in 3...45 { + let result = tables[i-1] + tables[i-2] + tables.append(result) + } + + return tables[n] + } +} \ No newline at end of file From 942ff4310d430a34c4a6978465558a1a4f9f83f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Sat, 12 Apr 2025 17:45:22 +0900 Subject: [PATCH 2/6] Solution Valid Anagram --- valid-anagram/doitduri.swift | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 valid-anagram/doitduri.swift diff --git a/valid-anagram/doitduri.swift b/valid-anagram/doitduri.swift new file mode 100644 index 000000000..9bfe37d56 --- /dev/null +++ b/valid-anagram/doitduri.swift @@ -0,0 +1,9 @@ +class Solution { + func isAnagram(_ s: String, _ t: String) -> Bool { + guard s.count == t.count else { + return false + } + + return s.sorted() == t.sorted() + } +} From 7fff63d1ad4a4369b7b1258f3b615f3b142994d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Sat, 12 Apr 2025 17:52:58 +0900 Subject: [PATCH 3/6] Solution Product of Array Except Self --- product-of-array-except-self/doitduri.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 product-of-array-except-self/doitduri.swift diff --git a/product-of-array-except-self/doitduri.swift b/product-of-array-except-self/doitduri.swift new file mode 100644 index 000000000..2c07588ca --- /dev/null +++ b/product-of-array-except-self/doitduri.swift @@ -0,0 +1,19 @@ +class Solution { + func productExceptSelf(_ nums: [Int]) -> [Int] { + let length = nums.count + var result = Array(repeating: 1, count: length) + var leftProduct = 1 + for i in 0.. Date: Sat, 12 Apr 2025 17:57:19 +0900 Subject: [PATCH 4/6] Solution 3sum --- 3sum/doitduri.swift | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 3sum/doitduri.swift diff --git a/3sum/doitduri.swift b/3sum/doitduri.swift new file mode 100644 index 000000000..de69a8a3f --- /dev/null +++ b/3sum/doitduri.swift @@ -0,0 +1,43 @@ +import Foundation + +class Solution { + func threeSum(_ nums: [Int]) -> [[Int]] { + var result = [[Int]]() + let sortedNums = nums.sorted() + + for i in 0.. 0 && sortedNums[i] == sortedNums[i - 1] { + continue + } + + var leftNumber = i + 1 + var rightNumber = sortedNums.count - 1 + + while leftNumber < rightNumber { + let sum = sortedNums[i] + sortedNums[leftNumber] + sortedNums[rightNumber] + + if sum < 0 { + leftNumber += 1 + } else if sum > 0 { + rightNumber -= 1 + } else { + result.append([sortedNums[i], sortedNums[leftNumber], sortedNums[rightNumber]]) + + while leftNumber < rightNumber && sortedNums[leftNumber] == sortedNums[leftNumber + 1] { + leftNumber += 1 + } + + while leftNumber < rightNumber && sortedNums[rightNumber] == sortedNums[rightNumber - 1] { + rightNumber -= 1 + } + + leftNumber += 1 + rightNumber -= 1 + } + } + } + + return result + } +} + From 3db0dbb6761bfc3991abb68da154894c11251d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Sat, 12 Apr 2025 18:06:04 +0900 Subject: [PATCH 5/6] Solution Validate Binary Search Tree --- validate-binary-search-tree/doitduri.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 validate-binary-search-tree/doitduri.swift diff --git a/validate-binary-search-tree/doitduri.swift b/validate-binary-search-tree/doitduri.swift new file mode 100644 index 000000000..90900369e --- /dev/null +++ b/validate-binary-search-tree/doitduri.swift @@ -0,0 +1,20 @@ +class Solution { + + func isValidBST(_ root: TreeNode?) -> Bool { + return isValid(root, nil, nil) + } + + private func isValid(_ node: TreeNode?, _ min: Int?, _ max: Int?) -> Bool { + guard let node = node else { return true } + + if let min = min, node.val <= min { + return false + } + + if let max = max, node.val >= max { + return false + } + return isValid(node.left, min, node.val) && isValid(node.right, node.val, max) + } +} + From 5a0ffe1d386cd4bdf79a9b5b2adb6dfef6979ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Mon, 14 Apr 2025 10:35:48 +0900 Subject: [PATCH 6/6] =?UTF-8?q?climbing=20stairs=20=EA=B3=B5=EB=B0=B1=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD=20=EB=B6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/doitduri.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/climbing-stairs/doitduri.swift b/climbing-stairs/doitduri.swift index 0a6bfc65a..528709b64 100644 --- a/climbing-stairs/doitduri.swift +++ b/climbing-stairs/doitduri.swift @@ -8,4 +8,4 @@ class Solution { return tables[n] } -} \ No newline at end of file +}