From 73260d1c2d0857b429a2a2c02762fa4255c09619 Mon Sep 17 00:00:00 2001 From: tigermint Date: Mon, 29 Jun 2026 10:08:58 +0900 Subject: [PATCH 1/2] feat: WEEK 02 solutions (climbing-stairs, valid-anagram) --- climbing-stairs/tigermint.kt | 16 ++++++++++++++++ valid-anagram/tigermint.kt | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 climbing-stairs/tigermint.kt create mode 100644 valid-anagram/tigermint.kt diff --git a/climbing-stairs/tigermint.kt b/climbing-stairs/tigermint.kt new file mode 100644 index 0000000000..6721569d5c --- /dev/null +++ b/climbing-stairs/tigermint.kt @@ -0,0 +1,16 @@ +class Solution { + fun climbStairs(n: Int): Int { + if (n == 1) return 1 + if (n == 2) return 2 + + val dp = IntArray(n + 1) { 0 } + dp[1] = 1 + dp[2] = 2 + + for (i in 3 .. n) { + dp[i] = dp[i - 1] + dp[i - 2] + } + + return dp[n] + } +} diff --git a/valid-anagram/tigermint.kt b/valid-anagram/tigermint.kt new file mode 100644 index 0000000000..472912c309 --- /dev/null +++ b/valid-anagram/tigermint.kt @@ -0,0 +1,20 @@ +class Solution { + fun isAnagram(s: String, t: String): Boolean { + val sCharToCount = mutableMapOf() + val tCharToCount = mutableMapOf() + + s.forEach { sCharToCount[it] = (sCharToCount[it] ?: 0) + 1 } + t.forEach { tCharToCount[it] = (tCharToCount[it] ?: 0) + 1 } + + val sKeys: MutableSet = sCharToCount.keys + val tKeys: MutableSet = tCharToCount.keys + + if (sKeys != tKeys) return false + sKeys.forEach { + if (sCharToCount[it] != tCharToCount[it]) { + return false + } + } + return true + } +} From 423d963d04c491682e9d50cd2f460c608a70db9f Mon Sep 17 00:00:00 2001 From: tigermint Date: Mon, 29 Jun 2026 17:46:45 +0900 Subject: [PATCH 2/2] feat: WEEK 02 solution (product-of-array-except-self) --- product-of-array-except-self/tigermint.kt | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 product-of-array-except-self/tigermint.kt diff --git a/product-of-array-except-self/tigermint.kt b/product-of-array-except-self/tigermint.kt new file mode 100644 index 0000000000..21a4e0c4b2 --- /dev/null +++ b/product-of-array-except-self/tigermint.kt @@ -0,0 +1,34 @@ +// class Solution { +// fun productExceptSelf(nums: IntArray): IntArray { +// val prefixProduct = IntArray(nums.size) { _ -> 1 } +// val suffixProduct = IntArray(nums.size) { _ -> 1 } + +// for (i in 1 until nums.size) { +// prefixProduct[i] = prefixProduct[i - 1] * nums[i - 1] +// } + +// for (i in nums.size - 2 downTo 0) { +// suffixProduct[i] = suffixProduct[i + 1] * nums[i + 1] +// } + +// return IntArray(nums.size) { prefixProduct[it] * suffixProduct[it] } +// } +// } + +class Solution { + fun productExceptSelf(nums: IntArray): IntArray { + val answer = IntArray(nums.size) { _ -> 1 } + + for (i in 1 until nums.size) { + answer[i] = answer[i - 1] * nums[i - 1] + } + + var right = 1 + for (i in nums.size - 1 downTo 0) { + answer[i] *= right + right *= nums[i] + } + + return answer + } +}