From 96ab933325951c91fb4a8b81280a6fedd36309b4 Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Fri, 1 Aug 2025 02:57:53 +0900 Subject: [PATCH 1/5] valid anagram solution --- valid-anagram/yhkee0404.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 valid-anagram/yhkee0404.go diff --git a/valid-anagram/yhkee0404.go b/valid-anagram/yhkee0404.go new file mode 100644 index 000000000..f99edf107 --- /dev/null +++ b/valid-anagram/yhkee0404.go @@ -0,0 +1,11 @@ +func isAnagram(s string, t string) bool { + sRune := []rune(s) + tRune := []rune(t) + sort.Slice(sRune, func(i, j int) bool { + return sRune[i] < sRune[j] + }) + sort.Slice(tRune, func(i, j int) bool { + return tRune[i] < tRune[j] + }) + return string(sRune) == string(tRune) +} From 437976fb080d3db18311b1c8c28767efd982716c Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Fri, 1 Aug 2025 03:13:25 +0900 Subject: [PATCH 2/5] climbing stairs solution --- climbing-stairs/yhkee0404.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 climbing-stairs/yhkee0404.scala diff --git a/climbing-stairs/yhkee0404.scala b/climbing-stairs/yhkee0404.scala new file mode 100644 index 000000000..e827fa996 --- /dev/null +++ b/climbing-stairs/yhkee0404.scala @@ -0,0 +1,11 @@ +object Solution { + def climbStairs(n: Int): Int = { + val dp = Array.ofDim[Int](n + 1) + dp(0) = 1 + dp(1) = 1 + for (i <- 2 to n) { + dp(i) = dp(i - 1) + dp(i - 2) + } + dp(n) + } +} From 9afbc0ba828aaca4584944f7968041b2386a49fd Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Fri, 1 Aug 2025 03:29:17 +0900 Subject: [PATCH 3/5] product of array except self solution --- product-of-array-except-self/yhkee0404.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 product-of-array-except-self/yhkee0404.rs diff --git a/product-of-array-except-self/yhkee0404.rs b/product-of-array-except-self/yhkee0404.rs new file mode 100644 index 000000000..dd488a31a --- /dev/null +++ b/product-of-array-except-self/yhkee0404.rs @@ -0,0 +1,16 @@ +impl Solution { + pub fn product_except_self(nums: Vec) -> Vec { + let mut ans = vec![1; nums.len()]; + let mut a = 1; + for i in (0..nums.len()).rev() { + ans[i] = a * nums[i]; + a = ans[i]; + } + a = 1; + for i in 0..nums.len() { + ans[i] = a * (if i == nums.len() - 1 {1} else {ans[i + 1]}); + a *= nums[i]; + } + return ans + } +} From 548eca88568dc283ad1771c60c53cae469f94e1f Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Fri, 1 Aug 2025 03:57:12 +0900 Subject: [PATCH 4/5] 3sum solution --- 3sum/yhkee0404.kt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 3sum/yhkee0404.kt diff --git a/3sum/yhkee0404.kt b/3sum/yhkee0404.kt new file mode 100644 index 000000000..cf159b024 --- /dev/null +++ b/3sum/yhkee0404.kt @@ -0,0 +1,31 @@ +class Solution { + fun threeSum(nums: IntArray): List> { + val ans = mutableListOf>() + nums.sort() + for (i in 0 until nums.size) { + if (i != 0 && nums[i] == nums[i - 1]) { + continue + } + var j = i + 1 + var k = nums.size - 1 + while (j < k) { + if (j != i + 1 && nums[j] == nums[j - 1]) { + j++ + continue + } + val u = nums[i] + nums[j] + while (j < k && u > - nums[k]) { + k-- + } + if (j >= k) { + break + } + if (u == - nums[k]) { + ans.add(listOf(nums[i], nums[j], nums[k])) + } + j++ + } + } + return ans + } +} From f9cc5cae3e6a69e80a5f45c613ee55fad946a7af Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Fri, 1 Aug 2025 04:09:39 +0900 Subject: [PATCH 5/5] validate binary search tree solution --- validate-binary-search-tree/yhkee0404.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 validate-binary-search-tree/yhkee0404.ts diff --git a/validate-binary-search-tree/yhkee0404.ts b/validate-binary-search-tree/yhkee0404.ts new file mode 100644 index 000000000..09fae741f --- /dev/null +++ b/validate-binary-search-tree/yhkee0404.ts @@ -0,0 +1,19 @@ +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ + +function isValidBST(root: TreeNode | null, left = - (1 << 30) * 2, right = - (left + 1)): boolean { + return root === null || root.val >= left && root.val <= right + && (root.left === null || root.val != (- (1 << 30) * 2) && isValidBST(root.left, left, root.val - 1)) + && (root.right === null || root.val != - (- (1 << 30) * 2 + 1) && isValidBST(root.right, root.val + 1, right)) +};