Algorithm
-
[알고리즘] #Move Zeroes■ Algorithm 2019. 7. 8. 00:01
출처 : https://leetcode.com/problems/move-zeroes/ Move Zeroes - 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 문제 Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output..
-
[알고리즘] #Reverse Linked List■ Algorithm 2019. 7. 7. 15:14
출처 : https://leetcode.com/problems/reverse-linked-list/ Reverse Linked List - 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 문제 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up: A linked list can be reversed either iteratively..
-
[알고리즘] #Invert Binary Tree■ Algorithm 2019. 7. 7. 14:08
출처 : https://leetcode.com/problems/invert-binary-tree/ Invert 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 문제 풀이 이 문제도 재귀함수를 이용해서 풀어주면 된다. 먼저 가장 최하단에 있는 왼쪽 자식과 오른쪽 자식의 값까지 내려간 뒤, 두 값을 바꿔준다.
-
[알고리즘] #Single Number■ Algorithm 2019. 7. 6. 23:56
출처: https://leetcode.com/problems/single-number/ Single Number - 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 문제 Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. C..
-
[알고리즘] #Merge Two Binary Trees■ Algorithm 2019. 7. 6. 20:56
출처: https://leetcode.com/problems/merge-two-binary-trees/ Merge Two Binary Trees - 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 Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are no..
-
[알고리즘] 방문 길이■ Algorithm 2019. 6. 24. 14:33
출처: https://programmers.co.kr/learn/courses/30/lessons/49994?language=java 알고리즘 연습 - 방문 길이 | 프로그래머스 programmers.co.kr 풀이 일단 U/D/R/L 방향에 따른 좌표 이동을 정리했다. 그리고 알고리즘을 정리해보면 아래와 같다. - 현재 좌표(0,0) 에서 시작. - 방향들이 적혀있는 String을 한글자씩 쪼개서 array에 저장 - array 순회 { 1. 방향에 따른 좌표 이동 2. 이동한 좌표가 좌표 평면 밖을 넘어가면 -> 1번으로 넘어가지 않는 경우 -> 3번으로 3. 현재 좌표에서 이동한 좌표로 이동한 길이 이미 지나간 길인지 확인 이미 지나간 길인 경우 -> 4번으로 처음 지나가는 길인 경우 -> 지나간 ..
-
[알고리즘] #Two Sum■ Algorithm 2019. 4. 17. 23:29
출처: LeetCode https://leetcode.com/problems/two-sum/ Two Sum - 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 Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, an..
-
[알고리즘] #완주하지 못한 선수■ Algorithm 2019. 4. 16. 10:32
출처: https://programmers.co.kr/learn/courses/30/lessons/42576 알고리즘 연습 - 완주하지 못한 선수 | 프로그래머스 실행 결과가 여기에 표시됩니다. programmers.co.kr 문제 설명 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수들의 이름이 담긴 배열 completion이 주어질 때, 완주하지 못한 선수의 이름을 return 하도록 solution 함수를 작성해주세요. 제한사항 마라톤 경기에 참여한 선수의 수는 1명 이상 100,000명 이하입니다. completion의 길이는 participant의 길이..