알고리즘_개념 및 문제풀이 (42) 썸네일형 리스트형 리트코드/leetcode/배열 중복 제거/remove-duplicates-from-sorted-array https://leetcode.com/problems/remove-duplicates-from-sorted-array Remove Duplicates from Sorted Array - 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 Solution only using O(1) Extra Memory (Array in-place) int removeDuplicates(vector& nums) { int length = 0; if(nums.size()==1){ re.. https://leetcode.com/problems/4sum/ If you approach it with BruteForce, u will get time exceeded on the Leetcode, So have to come up with the Hash Data Structure (Since Hash data structure has O(1) Time Complexity to find, it would be effective way to problem solving) First of all, We can think of the 4 Sum as 2 Sum + 2 Sum. So, if 2 Sum + 2 Sum equals to target, I can take that case into the answer array. 1. Using the Hash table,.. Leetcode/count_primes/Hash/리트코드 https://leetcode.com/problems/count-primes/submissions/ Count Primes - 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 에라토스테네스의 체로 품 Think of the array's index like the key in the Hash. Define the boolean array and let the index as the integer less than n, and let the value of the .. Leetcode/jewels and stones/해시/Hash https://leetcode.com/problems/jewels-and-stones/ Jewels and Stones - 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 It can be solved using the Hash. Put all S string's char as a key and count integer as a value. ('count integer' is how to calculate the n-times per each char as an .. 백준온라인저지(BOJ)/#9613//GCD(최대공약수)/C++/유클리드 호제법(Euclidean Algorithm) 24 와 16의 최대 공약수를 구해보자. 여기에서 유클리드 호제법 알고리즘을 사용하면 쉽게 구할 수 있다. 최대 공약수를 구하고자 하는 두 수에서 큰 수 a 를 작은수 b 로 나눈 나머지 r 과 기존의 작은수 b (24, 16) 으로 구한다고 생각하면, 24%16 = r 로 놓고, (24, 16) 대신 ( 16, r)에 대해 똑같은 방식으로 연산을 수행하여 숫자를 점점 줄여나간다. r 이 0이 되는 순간에 옆에 있는 숫자가 바로 GCD, 최대공약수가 된다. #include #include using namespace std; int gcd(int a, int b){ if(b == 0){ return a; } else{ return gcd(b, a%b); } } int main(){ int x,y; cin.. 완전 탐색- 재귀함수를 이용한 완전 탐색(기본 개념) 완전 탐색은, 말그대로 어떠한 답을 도출하기 위해 가능한 모든 케이스를 연산(완전탐색)하고 확인하여 답을 도출하는 알고리즘이다. 그러므로, 완탐의 시간복잡도는 아래와 같다. 완전탐색의 시간복잡도: 가능한 모든 경우의 수 이러한 완전탐색 알고리즘을 재귀함수를 통해 구현할 수 있다. 재귀함수는 자신이 수행할 작업을 유사한 형태의 여러 조각으로 쪼갠 뒤 그 중 한 조각을 수행하고, 나머지를 자기 자신을 호출해 실행하는 함수이다. ( 사실 알고리즘 문제풀이에 익숙하지 않으면, 자기 자신을 호출해 실행한다는 개념이 한 번에 받아들여지지는 않는다.. 인내를 갖고 반복해서 생각하는 것이 중요한 것 같다.) 재귀 함수는 Recursive Case, Base Case 두 가지로 크게 구성해서 설계하면 된다. 여기서 신기.. 프로그래머스/숫자게임/2018서머코딩기출/ https://programmers.co.kr/learn/courses/30/lessons/12987 알고리즘 연습 - 숫자 게임 | 프로그래머스 실행 결과가 여기에 표시됩니다. programmers.co.kr A팀과 B팀의 숫자를 오름차순으로 sort 한뒤, A팀의 작은 숫자부터 순회하면서 B팀에서 작은 숫자부터 비교하여, B팀에서 더 큰 숫자가 나오자마자, answer에 ++하고, 다음 B팀에서의 순회는 B팀에서 이전에 큰 숫자가 나온 index 다음 index부터 탐색해나간다. 구현코드 구현코드_ C++로 작성 #include #include #include #include using namespace std; int solution(vector A, vector B) { int answer = 0.. 프로그래머스/2018서머코딩기출/예산 https://programmers.co.kr/learn/courses/30/lessons/12982 알고리즘 연습 - 예산 | 프로그래머스 실행 결과가 여기에 표시됩니다. programmers.co.kr 낮은 예산을 필요로 하는 부서부터 순회하면서 balance에서 계속 -로 까주면서 코드 돌리면 된다. 쉬우니까 더 이상 말은 생략. [구현코드_C++] #include #include using namespace std; int solution(vector d, int budget) { int answer = 0; int balance = budget; //budget으로부터 balance를 값복사 한다. sort(d.begin(),d.end()); for(int i = 0; i < d.size(); .. 이전 1 2 3 4 5 6 다음