70. Climbing Stairs
·
Algorithm/LeetCode
문제You are climbing a staircase. It takes n steps to reach the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 2:Input: n = 3Output: 3Explanation: There are three ways to climb to the top.1 step + 1 step + 1 step1 step + 2 steps2 steps + 1 step링크: https://leetcode.com/problems/climbing-stairs/description/Solutionclass Solution { publ..
JDK와 JRE
·
Programming/Java
JDKJava Developmnet Kit개발과 실행을 위한 도구대표적으로 컴파일러(javac).java -> .calss 변환하여 JVM은 바이트코드(.class)를 기계어로 변환하여 실행JREJava Runtime Environment실행만을 위한 환경대표적으로 클래스 로더필요한 .class 파일을 메모리에 로드하여 JVM이 실행할 수 있도록 하는 역할
143. Reorder List
·
Algorithm/LeetCode
문제You are given the head of a singly linked-list. The list can be represented as:L0 → L1 → … → Ln - 1 → LnReorder the list to be on the following form:L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …You may not modify the values in the list's nodes. Only nodes themselves may be changed.링크: https://leetcode.com/problems/reorder-listSolution 1class Solution { public void reorderList(ListNode head) { if..
200. Number of Islands
·
Algorithm/LeetCode
문제전형적인 bfs 탐색 문제였다. 0은 물, 1은 땅을 의미하는 그래프 배열이 주어진다. 땅이 근접하게 모여 있으면 하나의 섬이다. 섬의 갯수를 요구하는 문제였다.링크: https://leetcode.com/problems/number-of-islands/description/Solutionclass Solution { static int[][] dirArray = {{-1,0},{1,0},{0,-1},{0,1}}; public int numIslands(char[][] grid) { int m = grid.length; int n = grid[0].length; boolean[][]visited = new boolean[m][n]; int ..
994. Rotting Oranges
·
Algorithm/LeetCode
문제그래프가 주어지고, 값은 0,1,2 중 하나이다. 1은 신선한 토마토, 2는 썩은 토마토, 0은 해당 위치에 토마토가 없음을 표현하였다. 썩은 토마토는 전염시킬 수 있어서, 근접 노드에 신선한 토마토가 있으면 전염시킨다. 전염은 1분 단위로 진행된다. 모든 토마토를 전염시키는데 걸리는 시간을 요구한다. 만약 모든 토마토를 전염시킬 수 없다면 -1를 반환한다.링크: https://leetcode.com/problems/rotting-oranges/?envType=study-plan-v2&envId=leetcode-75Solutionclass Solution { public int orangesRotting(int[][] grid) { int[][] visited = grid; ..
452. Minimum Number of Arrows to Burst Balloons
·
Algorithm/LeetCode
문제그리디 알고리즘 문제였다. 풍선의 위치(지름)가 범위로 표현되어 주어진다. 여러 풍선이 주어지고, 최대한 적은 갯수의 화살로 모든 풍선을 터트리는 문제였다. 풍선은 겹칠 수 있다(위치 범위가 일부 겹칠 수 있다). 그리디 알고리즘이란 Greedy(탐욕, 욕심쟁이) 이름 처럼 지금 당장 최적의 답을 선택하는 과정을 반복하여 결과를 도출하는 알고리즘이다. 링크: https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloonsSolution 1class Solution { public int findMinArrowShots(int[][] points) { int answer = 1; Arrays.sort(poi..
417. Pacific Atlantic Water Flow
·
Algorithm/LeetCode
문제그래프 탐색 문제이다. 2차원 배열의 그래프가 주어진다. 그래프는 섬을 의미한다. 각 노드의 value는 섬의 높이다. 인근 노드와의 높이 차이로 물이 흐른다. 각 노드를 시작으로 물이 흐를 때 Pacific Ocean(태평양)과 Atlantic Ocean(대서양) 까지 닿는 노드들을 찾는 문제이다.링크: https://leetcode.com/problems/pacific-atlantic-water-flow/description/Solutionclass Solution { final int[][] d = {{-1, 0},{1, 0},{0, -1},{0, 1}}; public List> pacificAtlantic(int[][] heights) { int m = heights.l..
Template Method Pattern
·
Programming/디자인 패턴
템플릿이란?템플릿 == 문자형 틀예를 들어, 색연필로 색칠할 때 색상은 바뀌어도 문자형은 유지되는 것처럼, 상위 클래스의 틀을 통해 기본적인 로직은 동일하게 유지템플릿 메서드 패턴이란?상위 클래스에서 처리의 뼈대를 결정하고 하위 클래스에서 그 구체적인 내용을 결정하는 패턴이다.구성(추상 클래스 + 구현 클래스)추상 클래스추상 클래스는 하위 클래스에서 구현할 것으로 기대하는 추상 메서드와 로직의 뼈대가 되는 템플릿 메서드로 구성된다.템플릿 메서드는 구체적인 로직의 순서를 정의한 일반 메서드로, 추상 메서드의 조합을 통해 알고리즘을 구성한다.템플릿 메서드 == 알고리즘Public abstract class AbstractDisplay {// 추상화 메서드(== 뼈대) public abstract vo..
207. Course Schedule
·
Algorithm/LeetCode
문제There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.Return true if you can finish all courses. Otherwise, return fal..
133. Clone Graph
·
Algorithm/LeetCode
문제원본 노드를 깊은 복사하는 문제이다. bfs를 사용했다.링크: https://leetcode.com/problems/clone-graph/Solution/*// Definition for a Node.class Node { public int val; public List neighbors; public Node() { val = 0; neighbors = new ArrayList(); } public Node(int _val) { val = _val; neighbors = new ArrayList(); } public Node(int _val, ArrayList _neighbors) { val = _..