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
7 changes: 7 additions & 0 deletions find-minimum-in-rotated-sorted-array/hozzijeong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @param {number[]} nums
* @return {number}
*/
var findMin = function(nums) {
return Math.min(...nums)
};
Copy link
Contributor

Choose a reason for hiding this comment

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

아마도 Math.min을 쓰시면 복잡도가 N이 될겁니다. 아래와 같은 constraint가 있습니다.
You must write an algorithm that runs in O(log n) time.

34 changes: 34 additions & 0 deletions maximum-depth-of-binary-tree/hozzijeong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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}
*/
var maxDepth = function(root) {
if(!root) return 0

const dfs = (node, level) =>{
if(!node) return level;

let left = level;
let right = level

if(node.left){
left = dfs(node.left, level+1)
}

if(node.right){
right = dfs(node.right, level+1)
}

return Math.max(left,right);
}

return dfs(root,1)
};
32 changes: 32 additions & 0 deletions merge-two-sorted-lists/hozzijeong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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}
*/

/**
* list는 오름 차순으로 정렬되어 있기 때문에 두 개의 리스트의 head가 더 작은 값이 listNode의 next에 순서대로 들어오게 하면 됩니다.
* list 둘 중하나가 없는 경우에는 나머지 다른 하나의 리스트를 반환합니다.
* 두 헤드 중에서 더 작은 값의 next에 재귀적으로 다음 링크드 리스트를 넘겨주면서 비교하는 방법으로 문제를 해결했습니다
*
*/

var mergeTwoLists = function(list1, list2) {
if(!list1 || !list2) return list1 || list2

if(list1.val < list2.val){
list1.next = mergeTwoLists(list1.next,list2)
return list1
}

list2.next = mergeTwoLists(list2.next,list1);

return list2;
};