본문 바로가기

algorithm63

하노이탑 문제 풀기 하노이탑 문제 풀기 import lombok.extern.slf4j.Slf4j; @Slf4j public class Hanoi { public static void main(String[] args) { int count = hanoi(3, 1, 2, 3, 0); log.info("{}", count); count = hanoi(4, 1, 2, 3, 0); log.info("{}", count); } /** * 하노이탑 원리를 이해해야 함. * 1. n-1 를 두번째 기둥으로 옮기고. * 2. 첫번째 기둥에서 마지막 원판을 세번째 기둥으로 옮긴다. * 3. 두번째 기둥에 있는 n-1 원판을 세번째 기둥으로 옮긴다. * * 위 내용을 보면 n 번쨰 기둥을 옮기는건 n-1 번째 기둥을 옮기는 것을 풀어야 풀.. 2020. 11. 5.
Hackerrank The Grid Search 풀이 The Grid Search 문제 : https://www.hackerrank.com/challenges/the-grid-search/problem 풀이 및 시간복잡도 주석에 풀이 및 시간 복잡도 써놓음. public class TheGridSearch { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int i = 0 ; i < t ; i++) { /** grid row */ int R = in.nextInt(); /** grid column */ in.. 2020. 10. 7.
leetcode Employees Earning More Than Their Managers 풀이 self 조인 leetcode 문제 https://leetcode.com/problems/employees-earning-more-than-their-managers/ 풀이 주의할 점은 a.managerId = b.id 임. a.managerId 가 3,4 = b 테이블과 비교했을 때, 1,2번이 조인 결과로 나옴. select a.name as Employee from Employee a inner join Employee b on a.managerId = b.Id where a.salary > b.salary ; 2020. 9. 30.
leetcode Reformat Department Table 풀이 CASE WHEN PIVOT LEETCODE 문제 https://leetcode.com/problems/reformat-department-table/ 요약하면 department 별 1~12월 수입을 출력. 풀이 select id ,sum(case when month = &#39;Jan&#39; then revenue end) as Jan_Revenue ,sum(case when month = &#39;Feb&#39; then revenue end) as Feb_Revenue ,sum(case when month = &#39;Mar&#39; then revenue end) as Mar_Revenue ,sum(case when month = &#39;Apr&#39; then revenue end) as .. 2020. 9. 29.