코딩테스트 17

[leetcode] Product of Array Except Self

https://leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 인덱스 위치의 요소를 제외한 모든 요소를 곱한 결과를 구하는 문제입니다. [1,2,3,4] 배열이 주어졌다면, [ 2*3*4, 1*3*4, 1*2*4, 1*2*3 ]으로 반환합니다. 제가 구현한 코드입니다. 저는 모든 요소를 곱한 뒤, 각 요소로 나눠주면 ..

[leetcode] Maximum Product Subarray

https://leetcode.com/problems/maximum-product-subarray/ Maximum Product Subarray - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 연속된 수를 곱한 결과 중 가장 큰 것을 찾아내는 문제입니다. 음수 * 음수 = 양수인 케이스를 고려해야 합니다. 곱셈의 결과가 음수가 된 경우에는 min (최소값)으로 저장해둡니다. 여기에 다시 음수를 곱하게 되면, 곱셈의 결과를 max(최대값)으로 저장합니다. 이렇게..

[leetcode] three sum

https://leetcode.com/problems/3sum 3Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com package leetcode; import java.util.Arrays; import java.util.LinkedList; import java.util.List; /* * 문제주소 : https://leetcode.com/problems/3sum/ * 난이도 : 미디움 * 문제 내용 요약 : 주어진 배열에서 3개 숫자를 꺼냄. 3개 숫..

[SQL] leetCode Department Top Three Salaries

https://leetcode.com/problems/department-top-three-salaries/ Department Top Three Salaries - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 부서별로 연봉순위 3위까지 출력하는 문제입니다. 단 동일한 연봉인 경우 동일 순위로 판단합니다. (1등이 2명이더라도 다음 순위는 2등으로 판별) DENSE RANK 함수를 사용하였습니다. [Oracle 풀이] SELECT D.NAME AS Depart..

리트코드 leetCode 743.Network Delay Time

문제 : https://leetcode.com/problems/network-delay-time/ Network Delay Time - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 : 다익스트라 알고리즘 사용 2021.09.19 - [알고리즘/알고리즘] - 다익스트라 알고리즘 Dijkstra's algorithm 구현 JAVA class Solution { public int networkDelayTime(int[][] times, int n, int k..

프로그래머스 가장 먼 노드

문제 : https://programmers.co.kr/learn/courses/30/lessons/49189 풀이 : ① BFS를 이용해 1부터 특정 노드까지의 경로를 탐색 후 거리를 저장 ② 탐색한 거리 중 가장 먼 거리의 갯수를 세어 반환 2021.09.19 - [알고리즘/알고리즘] - 너비 우선 탐색 Breath-first Search BFS 구현JAVA import java.util.*; class Solution { public int solution(int n, int[][] edges) { // 방문여부를 저장할 배열 boolean[] isVisited = new boolean[n+1]; // 지점별 1과의 거리를 저장할 배열 int[] distance = new int[n+1]; //ed..

리트코드 leetCode binary-tree-right-side-view

문제 : https://leetcode.com/problems/binary-tree-right-side-view/ Binary Tree Right Side View - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 : 모든 레벨에서 가장 오른쪽에 있는 노드만을 찾아 저장해야 하는 문제. ① 재귀로 구현 > 오른쪽 노드를 탐색하는 부분을 먼저 수행하면서 값을 저장하도록 위치를 조정함. - 오른쪽 노드 탐색 - 왼쪽 노드를 탐색 ② 더 이상 자식 노드가 없으면..

프로그래머스 단어변환

문제 : https://programmers.co.kr/learn/courses/30/lessons/43163 코딩테스트 연습 - 단어 변환 두 개의 단어 begin, target과 단어의 집합 words가 있습니다. 아래와 같은 규칙을 이용하여 begin에서 target으로 변환하는 가장 짧은 변환 과정을 찾으려고 합니다. 1. 한 번에 한 개의 알파벳만 바꿀 수 programmers.co.kr 풀이 : ① DFS를 이용핸 도달할 수 있는 모든 경로를 탐색. ② 탐색 한 경로의 최소값을 출력 2021.09.19 - [알고리즘/알고리즘] - 깊이 우선 탐색 Depth-first search 깊이 우선 탐색 Depth-first search 깊이 우선 탐색 시작 노드와 직접 연관된 하위 노드 끝까지 모두 ..

프로그래머스 네트워크

문제 : https://programmers.co.kr/learn/courses/30/lessons/43162 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr 풀이 : BFS를 이용해 지점을 잇는 경로를 탐색 ① 지점을 잇는 경로를 탐색한다. ② ①에서 탐색되지 않은 지점를 시작으로 재탐색한다. * computer[i][i] 가 1이므로, 어느 지점과 연결되지 않으면 자기자신하고만 연결되는 경로 (네트워크) 1개가 세어진다. 2021.09.19 - [알고리즘/알고리즘] - 너비 우선 탐색 Breath-f..