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
36 changes: 36 additions & 0 deletions invert-binary-tree/robinyoon-dev.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: DFS
  • 설명: 이 코드는 재귀를 이용하여 이진 트리의 좌우 자식을 교환하는 방식으로, 깊이 우선 탐색(DFS) 패턴에 속합니다. 재귀 호출을 통해 트리의 모든 노드를 방문하며 작업을 수행합니다.

📊 시간/공간 복잡도 분석

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

피드백: 모든 노드를 방문하여 좌우 자식을 교환하므로 시간 복잡도는 노드 수에 비례하는 O(n)입니다. 재귀 호출로 인해 호출 스택이 트리의 높이만큼 쌓이므로 공간 복잡도는 트리의 높이 O(h)입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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 {TreeNode}
*/
var invertTree = function (root) {

let node = root;

let result = changeLeftAndRight(node);

return result;

function changeLeftAndRight(root) {
// 종료 조건
if (root === null) return root;

tempLeft = root.left;
tempRight = root.right;

root.left = tempRight;
root.right = tempLeft;

changeLeftAndRight(root.left);
changeLeftAndRight(root.right);

return root;
}
};
16 changes: 16 additions & 0 deletions search-in-rotated-sorted-array/robinyoon-dev.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
  • 설명: 이 코드는 배열을 선형 탐색하여 타겟을 찾는 방식으로, 이진 탐색과는 다르지만, 검색 문제에서 흔히 사용하는 패턴입니다. 그러나 주어진 코드에는 명시적 이진 탐색 구현이 없으므로 정확한 패턴은 'Binary Search'로 간주하기 어렵습니다. 따라서 패턴 목록에는 포함하지 않는 것이 적절합니다.

📊 시간/공간 복잡도 분석

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

피드백: 배열 전체를 순회하므로 시간 복잡도는 배열 크기 n에 비례하는 O(n)입니다. 추가적인 공간은 사용하지 않으므로 O(1)입니다.

개선 제안: 이진 탐색을 활용하면 시간 복잡도를 O(log n)으로 개선할 수 있습니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
var search = function(nums, target) {
let targetIndex = -1;

for(let i = 0; i < nums.length; i++){
if(nums[i] === target){
targetIndex = i;
break;
}
}
return targetIndex;
};
Loading