Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions 3sum/tedkimdev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// TC: O(n^2)
// SC: O(m)
func threeSum(nums []int) [][]int {
result := make(map[[3]int]struct{})

sort.Ints(nums)

// target value = nums[k]
for k := 0; k < len(nums); k++ {
left := 0
if k == left {
left = 1
}
right := len(nums) - 1
if k == right {
right = len(nums) - 2
}

target := nums[k]
for left < right {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반본묵 문법이 신기하네요
옛~날에 배운걸 떠올려보면 반복문이 for문으로 통일되어 있던것 같은데 맞나요?

Copy link
Copy Markdown
Contributor Author

@tedkimdev tedkimdev Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞습니다. 이 경우는 while 문으로 보시면 될 것 같아요.

sum := nums[left] + nums[right] + target
if sum == 0 {
if left > k {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

중복제거를 key 통일 방식으로 해결하셨군요
근데 이렇게하면 중복되는 케이스들도 연산이 필수적이되어서
중복확인을 먼저수행하는 케이스보다 효율이 조금 떨어질 것 같은데
어떻게 생각하시나요?

Copy link
Copy Markdown
Contributor Author

@tedkimdev tedkimdev Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sum 계산하기 전에 key 중복 확인을 먼저하는게 효율이 좋을거 같다는 말씀이시죠?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니다

result[[3]int{nums[k], nums[left], nums[right]}] = struct{}{}
} else if left < k && k < right {
result[[3]int{nums[left], nums[k], nums[right]}] = struct{}{}
} else if k > right {
result[[3]int{nums[left], nums[right], nums[k]}] = struct{}{}
}
}
if sum < 0 {
left++
if k == left {
left++
}
} else {
right--
if k == right {
right--
}
}
}

}

filteredResult := [][]int{}
for k, _ := range result {
filteredResult = append(filteredResult, k[0:len(k)])
}

return result.keys()
}
18 changes: 18 additions & 0 deletions climbing-stairs/tedkimdev.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// TC: O(n)
// SC: O(1)
impl Solution {
pub fn climb_stairs(n: i32) -> i32 {
if n <= 2 {
return n;
}

let mut arr: [i32; 2] = [1, 2];
let mut current = 0;
for n in 3..=n {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명이 반복되어 오해의 소지가 있는 것 같습니다!
사용되지 않으니 언더바로 처리하는건 어떨까요?

Copy link
Copy Markdown
Contributor Author

@tedkimdev tedkimdev Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게요. 사용안하고 있었네요. 감사합니다.

current = arr[0] + arr[1];
arr[0] = arr[1];
arr[1] = current;
}
current
}
}
24 changes: 24 additions & 0 deletions product-of-array-except-self/tedkimdev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// TC: O(n)
// SC: O(n)
func productExceptSelf(nums []int) []int {
result := make([]int, 0)

left := make([]int, len(nums))
left[0] = 1

right := make([]int, len(nums))
right[len(nums)-1] = 1

for i := 1; i < len(nums); i++ {
left[i] = nums[i-1] * left[i-1]
}

for i := len(nums) - 2; i >= 0; i-- {
right[i] = nums[i+1] * right[i+1]
}

for i := 0; i < len(nums); i++ {
result = append(result, left[i]*right[i])
}
return result
}
Comment on lines +3 to +24
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오! left와 right 배열을 각각 만들어서 계산하셨군요.
left 결과가 담긴 배열에 오른쪽 누적곱을 바로 곱해주면 배열 하나로도 풀 수 있을 것 같아요! (문법이 엄청 신기하네요 ㅎㅎ)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 읽고 이해하기가 불편해서 for 문을 나눠버렸었네요. 리뷰 감사합니다.

18 changes: 18 additions & 0 deletions valid-anagram/tedkimdev.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// TC: O(n) - n is the length of the strings
// SC: O(1) - lowercase english letters
impl Solution {
pub fn is_anagram(s: String, t: String) -> bool {
if s.len() != t.len() {
return false;
}

let mut count_map: HashMap<u8, i32> = HashMap::new();

for (a, b) in s.bytes().zip(t.bytes()) {
*count_map.entry(a).or_insert(0) += 1;
*count_map.entry(b).or_insert(0) -= 1;
}

count_map.values().all(|&v| v == 0)
}
}
42 changes: 42 additions & 0 deletions validate-binary-search-tree/tedkimdev.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Definition for a binary tree node.
// #[derive(Debug, PartialEq, Eq)]
// pub struct TreeNode {
// pub val: i32,
// pub left: Option<Rc<RefCell<TreeNode>>>,
// pub right: Option<Rc<RefCell<TreeNode>>>,
// }
//
// impl TreeNode {
// #[inline]
// pub fn new(val: i32) -> Self {
// TreeNode {
// val,
// left: None,
// right: None,
// }
// }
// }

use std::rc::Rc;
use std::cell::RefCell;

// TC: O(n)
// SC: O(n) - skewed tree
impl Solution {
pub fn is_valid_bst(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
is_valid(root, i64::MIN, i64::MAX)
}
}
fn is_valid(node: Option<Rc<RefCell<TreeNode>>>, left: i64, right: i64) -> bool {
if let Some(n) = node {
let node_ref = n.borrow();
let val = node_ref.val as i64;

if val <= left || val >= right {
return false;
}
return is_valid(node_ref.left.clone(), left, val)
&& is_valid(node_ref.right.clone(), val, right);
}
true
}
Loading