■ 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. 26. 16:14
출처 : https://programmers.co.kr/learn/courses/30/lessons/12938 알고리즘 연습 - 최고의 집합 | 프로그래머스 programmers.co.kr 문제 설명 자연수 n 개로 이루어진 집합 중에 다음 두 조건을 만족하는 집합을 최고의 집합이라고 합니다. 각 원소의 합이 S가 되는 수의 집합 위 조건을 만족하면서 각 원소의 곱 이 최대가 되는 집합 예를 들어서 자연수 2개로 이루어진 집합 중 합이 9가 되는 집합은 다음과 같이 4개가 있습니다. { 1, 8 }, { 2, 7 }, { 3, 6 }, { 4, 5 } 그중 각 원소의 곱이 최대인 { 4, 5 }가 최고의 집합입니다. 집합의 원소의 개수 n과 모든 원소들의 합 s가 매개변수로 주어질 때, 최고의 집합을 r..
-
[알고리즘] 방문 길이■ 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번으로 처음 지나가는 길인 경우 -> 지나간 ..
-
[알고리즘] #체육복■ Algorithm 2019. 5. 28. 09:00
출처 : https://programmers.co.kr/learn/courses/30/lessons/42862?language=javascript 알고리즘 연습 - 체육복 | 프로그래머스 점심시간에 도둑이 들어, 일부 학생이 체육복을 도난당했습니다. 다행히 여벌 체육복이 있는 학생이 이들에게 체육복을 빌려주려 합니다. 학생들의 번호는 체격 순으로 매겨져 있어, 바로 앞번호의 학생이나 바로 뒷번호의 학생에게만 체육복을 빌려줄 수 있습니다. 예를 들어, 4번 학생은 3번 학생이나 5번 학생에게만 체육복을 빌려줄 수 있습니다. 체육복이 없으면 수업을 들을 수 없기 때문에 체육복을 적절히 빌려 최대한 많은 학생이 체육수업을 들어야 합니다. 전체 programmers.co.kr 문제 설명 점심시간에 도둑이 들어,..