본문 바로가기

Algorithm42

[Leetcode(릿코드)] 378. Kth Smallest Element in a Sorted Matrix (Medium) Binarysearch 문제 leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/ Kth Smallest Element in a Sorted Matrix - 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 문제 2차원 배열이 주어진다 각 배열은 정렬이 되어있다 예를 들면, matrix = [[1, 5, 9], [10, 11, 13], [12, 13, 15] ], k = 8 이 주어지면, 1 5 9 10 1.. 2020. 11. 3.
[Leetcode(릿코드)] 107. Binary Tree Level Order Traversal II (Easy) BFS 문제 leetcode.com/problems/binary-tree-level-order-traversal-ii/ Binary Tree Level Order Traversal II - 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 문제 이진트리를 BFS로 탐색한 후, 같은 레벨끼리 리스트로 묶어서 리턴하는 문제이다 해결 2가지 방식으로 풀었다 1. BFS로 탐색한 후, 가장 상위 레벨의 노드부터 호출하기 위해 스택에 담아 리턴한다 static void bf.. 2020. 11. 1.
[Leetcode(릿코드)] 111. Minimum Depth of Binary Tree (Easy) BFS 문제 leetcode.com/problems/minimum-depth-of-binary-tree/ Minimum Depth of Binary Tree - 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 문제 루트 노드에서 시작해서 리프 노드까지 가장 짧은 거리를 구하는 문제이다 dfs 문제에서 골랐는데, bfs로 푸는 게 더 적합한 듯하다 해결 BFS로 탐색하다가 자식노드가 없으면 더이상 탐색하지 않는다 private static int bfs(TreeNo.. 2020. 11. 1.
[Leetcode(릿코드)] 441. Arranging Coins (Easy) Binarysearch 문제leetcode.com/problems/arranging-coins/Arranging Coins - LeetCodeLevel 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..+k 2020. 10. 28.
[Leetcode(릿코드)] 349. Interserction of Two Arrays (Easy) BinarySearch 문제 leetcode.com/problems/intersection-of-two-arrays/ Intersection of Two Arrays - 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 문제 두 배열의 교집합을 구하는 문제이다 ex) nums1 = [1,2,2,1], num2= [2,2] 답은 [2] 해결 2가지 방식으로 풀었다 Runtime은 Set은 6~7ms / BinarySearch가 5ms 걸렸다 1. Set (O(n)) .. 2020. 10. 27.
[Leetcode(릿코드)] 746. Min Cost Climbing Stairs (Easy) DP 문제 leetcode.com/problems/min-cost-climbing-stairs/ Min Cost Climbing Stairs - 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 문제 Input으로 cost 배열이 주어진다 ex) cost = [10,15,20] 시작해서 배열의 마지막을 넘어서 도착해야하는데, 가장 최소의 비용으로 도달해야한다 점프는 한번할 때, 1 또는 2로 뛸 수 있다 예를들어, [10,15,20]일 때, [시작 10 15 20 .. 2020. 10. 25.
[Hackerrank] Number Line Jumps (Easy) [Hackerrank] Number Line Jumps - (Implemetation - Easy) www.hackerrank.com/challenges/kangaroo/problem Number Line Jumps | HackerRank Can two kangaroo meet after making the same number of jumps? www.hackerrank.com 문제 캥거루 2마리가 뛴다 캥거루1은 항상 캥거루2보다 앞에 있다 같은 점프횟수로 두 캥거루가 같아지는 지점이 있으면 YES 아니면 NO를 출력한다 예를들어 0 3 4 2면, 캥거루 1이 0에서 시작, 점프:3 캥거루 2는 4에서 시작, 점프:2 0 3 6 9 12 4 6 8 10 12 두 캥거루 모두 5번의 점프로 12로 같아.. 2020. 10. 23.