본문 바로가기

전체 글351

[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.
[java] 자바 기본 문법 @override 자꾸 잊어버리는 내 자신을 위한 포스팅.... 자바 공부를 열심히 해야겠다 자바의 핵심 개념인 객체(class) 그리고 상속(extends)! 왜 쓸까? 오버라이딩을 오타없이 하기 위해... 오버라이딩이란? 부모 클래스(super class)에 존재하는 필드나 메서드를 자식 클래스(sub class)에서 재정의하여 사용하는 것. 즉 부모 클래스의 이미 정의된 (주로) 함수를 약간 바꾸고 싶다! 하면 사용한다. 오버라이딩을 통해 슈퍼클래스를 부르고 싶다면 super()을 쓰면 된다. @override의 사용 이유 오버라이딩을 하려면 서브 클래스에 슈퍼 클래스 함수와 동일한 이름으로 정의되어야 한다. 그런데 적다보면 오타도 나고..오타가 나서 다른 함수가 적히면 아예 새로운 함수가 생성되는 것! 그래서 이런.. 2020. 10. 2.
[leetcode 560] Subarray Sum Equals K Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k = 2 Output: 2 Constraints: The length of the array is in range [1, 20,000]. The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7]. 풀이: 처음 접근한 방법은 투포인터...하지만 투포인터가 작동하려면 배열 안의 수가 전부 양수라는 조건이 있어야 .. 2020. 10. 1.