알고리즘 43

[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..

[SQL] leetcode Second Highest Salary

https://leetcode.com/problems/second-highest-salary/ Second Highest Salary - 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 두번째로 연봉이 높은 직원을 출력하는 문제입니다. 풀이 : rank over 윈도우 함수 사용 [Oracle 풀이] select sum(salary) as "SecondHighestSalary" from ( select salary, rank() over (order by sala..

[SQL] leetcode Trips and Users

문제 : https://leetcode.com/problems/trips-and-users/ Trips and Users - 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 banned된 고객이 신청한게 아닌 예약들 중에 취소된 비율을 구하는 문제입니다. 오라클 Oracle 풀이 SELECT request_at as Day ,round(COUNT(case status when 'cancelled_by_driver' then 1 when 'cancelled_by_c..

리트코드 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 풀이 : 모든 레벨에서 가장 오른쪽에 있는 노드만을 찾아 저장해야 하는 문제. ① 재귀로 구현 > 오른쪽 노드를 탐색하는 부분을 먼저 수행하면서 값을 저장하도록 위치를 조정함. - 오른쪽 노드 탐색 - 왼쪽 노드를 탐색 ② 더 이상 자식 노드가 없으면..