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
30 changes: 30 additions & 0 deletions find-minimum-in-rotated-sorted-array/seongmin36.js

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search
  • 설명: 회전된 정렬 배열에서 최소값을 이진 탐색으로 찾는 알고리즘으로, 중간 인덱스를 확인해 탐색 구간을 반으로 축소한다. O(log n)의 시간 복잡도와 O(1)의 공간 복잡도를 갖는다.

📊 시간/공간 복잡도 분석

복잡도
Time O(log n)
Space O(1)

피드백: 중간값 비교를 통해 회전점 인근으로 범위를 점진 축소한다. 공통적으로 좌우 중 어느 쪽이 더 큰지에 따라 탐색 구간을 반으로 줄인다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
이진탐색을 이용한 풀이

TC: O(log n)
SC: O(1)
*/
/**
* @param {number[]} nums
* @return {number}
*/
function findMin(nums) {
let left = 0;
let right = nums.length - 1;

if (nums[left] <= nums[right]) return nums[left]; // 일자 배열인 경우

while (left < right) {
let mid = Math.floor((left + right) / 2);

if (nums[mid] > nums[mid + 1]) return nums[mid + 1]; // mid의 바로 옆에서 초기화되는 경우

if (nums[mid] > nums[right]) {
Comment on lines +17 to +22

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

Choose a reason for hiding this comment

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

그렇네요, 회전된 정렬 배열이라는 점에서 최솟값을 바로 찾을 수 있겠네요! 피드백 감사합니다 ☺️

left = mid + 1;
} else {
right = mid;
}
}

return nums[left];
}
25 changes: 25 additions & 0 deletions maximum-depth-of-binary-tree/seongmin36.js

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Binary Search
  • 설명: 코드는 이진 트리를 재귀적으로 좌우로 탐색하며 깊이를 구한다. 자식 노드로의 탐색은 DFS의 전형적 형태이고, 재귀를 통한 깊이 축적이 핵심이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(h)

피드백: 리프까지 모든 노드를 한 번씩 방문하며 재귀로 깊이를 계산한다. 최악의 경우 트리의 높이가 공간 복잡도에 영향

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
이 문제를 푸는 핵심은 DFS(깊이 우선 탐색)다.
왼쪽으로, 오른쪽으로 쭉 들어가는 값을 반환해서 변수에 저장한다.
이를 재귀호출하면 쉽게 해결할 수 있다.
*/
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
function maxDepth(root) {
if (root === null) return 0;

let left_depth = maxDepth(root.left);
let right_depth = maxDepth(root.right);

return Math.max(left_depth, right_depth) + 1;
}
38 changes: 38 additions & 0 deletions merge-two-sorted-lists/seongmin36.js

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.

O(1) 공간복잡도와 O(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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Linked List
  • 설명: 두 정렬 리스트를 하나로 합치기 위해 두 포인터(list1,list2)로 값을 비교하고 작은 노드를 차례대로 연결하는 전형적인 투 포인터 방식의 연결 리스트 병합 패턴.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 가상 머리(dummy) 노드를 사용해 비교하며 결과를 구성한다. 남은 노드를 연결하는 부분까지 일관되게 처리

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
list1, list2는 시작 노드 객체
핵심은 '가위바위보 기찻길 룰'
cur.next가 list1, list2 비교 결과를 배치해주는 역할

TC : O(n)
SC : O(1)
*/
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} list1
* @param {ListNode} list2
* @return {ListNode}
*/
function mergeTwoLists(list1, list2) {
let dummy = new ListNode();
let cur = dummy;

while (list1 && list2) {
if (list1.val > list2.val) {
cur.next = list2;
list2 = list2.next;
} else {
cur.next = list1;
list1 = list1.next;
}
cur = cur.next;
}
cur.next = list1 || list2; // 남아있는 원소 붙이기

return dummy.next;
}
Loading