본문 바로가기

분류 전체보기351

[leetcode 102] Binary Tree Level Order Traversal 같은 레벨의 노드끼리 배열을 만들어 return한다. Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], return its level order traversal as: [ [3], [9,20], [15,7] ] 풀이 - 큐와 bfs를 이용하여 레벨 별로 노드를 저장한다. /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNod.. 2020. 10. 3.
[leetcode 993] Cousins in Binary Tree - 두 노드가 부모가 다르고 같은 depth를 가진 cousin인지 확인하기 In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. Two nodes of a binary tree are cousins if they have the same depth, but have different parents. We are given the root of a binary tree with unique values, and the values x and y of two different nodes in the tree. Return true if and only if the nodes corre.. 2020. 10. 3.
[leetcode 1022] Sum of Root To Leaf Binary Numbers You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13. For all leaves in the tree, consider the numbers represented by the path from the root to that leaf. Return the sum of these .. 2020. 10. 3.
[java] extends vs implements extends - 상속 - 클래스에서 사용 - 슈퍼클래스에 정의된 필드와 매서드 사용 가능 - 또 다른 특징은 .... 다중 상속이 불가능하다는 것! 다중 상속이란 부모 클래스가 2개 이상 존재하는 것을 의미한다. 즉 무조건 하나의 슈퍼 클래스만 상속 가능하다는 의미다. public class Son extends Mother, Father....가 불가능하다! 자바가 다중 상속을 지원하지 않기에 등장한 것... 그것이 바로 인터페이스다. implements - 역시 상속을 의미한다. - 인터페이스에서 사용 - 여러 개 상속 가능: public class Son implements Mother, Father 가능하다 - 가장 큰 특징은 부모의 메서드를 반드시 오버라이딩(재정의)해야 한다는 것이다. -> .. 2020. 10. 2.