본문 바로가기

[OJ.leetcode] balanced-binary-tree https://oj.leetcode.com/problems/balanced-binary-tree/ Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. /* solution: modified preorder (O(n)) 매 순회마다 left, right 의 depth를 비교해서 >1 이면 return false more than 1 이라고 했으므로 인터뷰어와 1 와 같은 예제도 .. 더보기
[Oj.leetcode] remove-element https://oj.leetcode.com/problems/remove-element/ Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. /* 이런 단순한 문제 일수록 문제의 의도를 정확하게 파악하기 위해 인터뷰어와 코딩 전 충분한 사전 토의가 필요. 단순히 주어진 element를 모두 지우고 새로운 length를 리턴하라는 것인지, remove후 정렬절차가 어떻게 될것인지 질문하기. "The order of el.. 더보기
[OJ.leetcode] merge-two-sorted-lists https://oj.leetcode.com/problems/merge-two-sorted-lists/ Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. /* 단순히 two runner를 이용해서 merge sort의 merge와 마찬가지로 O(n)에 sorted list를 merge 하는 알고리즘 한번에 accepted 했어야했는데.. linked list pointing 헷갈려서 2번 실패. 아직 pointer 부분 부족한듯 */ /** * Definition for singly-linked list... 더보기