전체 글

공부를 야무지게 해보겠습니다!! (알고리즘, 자료구조 문제 풀이 학습 및 기록)
문제 https://leetcode.com/problems/candy/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: ratings = [1,0,2] Output: 5 Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively. Example 2: Input: ratings = [1,2,2] Output: 4 Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively. The third ch..
문제 https://leetcode.com/problems/insert-delete-getrandom-o1/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input ["RandomizedSet", "insert", "remove", "insert", "getRandom", "remove", "insert", "getRandom"] [[], [1], [2], [2], [], [1], [2], []] Output [null, true, false, true, 2, true, false, 2] Explanation RandomizedSet randomizedSet = new RandomizedSet(); randomizedSet.insert(1)..
문제 https://leetcode.com/problems/h-index/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: citations = [3,0,6,1,5] Output: 3 Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations e..
문제 https://leetcode.com/problems/jump-game-ii/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: nums = [2,3,1,1,4] Output: 2 Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index. Example 2: Input: nums = [2,3,0,1,4] Output: 2 Constraints: 1
· Java
📌 Override 오버라이드는 상위메서드를 무시하고 하위에서 재정의 하는 것이다. 우리는 부모의 메서드를 오버라이드 할 때 @Override 어노테이션을 붙여준다. 그렇다면 아래의 코드를 실행시키면 어떻게 될까? class Parent { public void hello(String name) { System.out.println("안녕하세요, 저는 " + name + "입니다."); } } class Child extends Parent{ @Override public void hello() { System.out.println("안녕!"); } } 컴파일 에러가 발생한다. 에러내용은 아래와 같다. java: method does not override or implement a method from..
· Java
앞에서 객체 지향 프로그래밍(Object-Oriented Programming, OOP)이 가지고 있는 4가지 핵심인 추상화, 캡슐화, 상속, 다형성을 알아보았다. 그렇다면 이러한 4가지 특징 중에서 인터페이스가 가지고 있는 객체지향의 특징에는 어떠한 것들이 있을까? 📌 인터페이스와 추상화 앞에서 추상화의 예시를 인터페이스로 든 적이 있다. public interface Animal { public void eat(); // 추상메서드 } 인터페이스는 메서드의 세부내용을 보여주지 않고, 메서드이름, 파라미터, 반환타입등을 통해서 어떠한 동작을 수행하는지에 대한 정보만을 보여준다. 사용자는 이러한 추상적인 정보만을 이용해서 기능을 사용하고, 실제 구현은 개발자가 구현체에서 구현하고 있다. 인터페이스는 "나..
· Java
📌 추상화, 캡슐화, 상속, 다형성 이란? 객체 지향 프로그래밍(Object-Oriented Programming, OOP)이 가지고 있는 4가지 핵심 개념이다. 1. 추상화란? "사용자는 설명서를 보고 기능을 사용하고, 내부 구현 방법은 모른다" 자바에서는 인터페이스 키워드 implements를 활용해서 구현할 수 있다. 아래 예시를 보자. 사용자는 Car 인터페이스를 보고 "Car 타입에는 return 값이 void인 go() 메서드가 있구나" 하고 생각하고 go() 메서드를 사용한다. 개발자는 Car 타입의 실제 구현체인 Avante 클래스에 go() 메서드를 구현한다. Car 인터페이스는 앞으로가기, 정지하기와 같이 역할을 나타내고 있다. Aante는 실제 구현을 나타내고 있다. // Car 타입..
문제 https://leetcode.com/problems/clone-graph/ 더보기 Example 1: Example 2: Input: adjList = [[]] Output: [[]] Explanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors. Example 3: Input: adjList = [] Output: [] Explanation: This an empty graph, it does not have any nodes. Constraints: The number of nodes in the grap..
· Java
String 클래스를 잘못사용할 때 문제점 String은 내부에서 char [] 배열로 이루어진 자료구조이다. 또한 내부 문자열 변경이 불가능하고 final class로 선언되어 있기 때문에 더 이상 상속이나 확장이 불가능하다. 하지만 String을 사용함에 있어서 잘못 사용하면 GC(Garbage Collection)가 많이 발생하는 문제가 생긴다. 예를 들어 아래와 같은 코드가 있을 때 str은 기존에 str에 값을 더해주는 것이 아니라 새로운 String 클래스 객체를 생성하게 된다. String str = "aaa"; for (int i = 0; i < 5; i++) { str = str + "b"; } 그러므로 반복되는 작업만큼 계속해서 객체가 생기게 되고, 더해질 때마다 사용되지 않는 객체는 ..
문제 https://leetcode.com/problems/implement-trie-prefix-tree/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input ["Trie", "insert", "search", "search", "startsWith", "insert", "search"] [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]] Output [null, null, true, false, true, null, true] Explanation Trie trie = new Trie(); trie.insert("apple"); trie.search("apple"); // ..
Don't stop 훈
쉬지마 정지훈