본문 바로가기

리트코드/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..
혼자 간단히 정리하는 AWS 기본 개념 (EC2 기본 개념과 기능) AWS, 아마존에서 제공하는 클라우드 서버 개념이다. 여기서 클라우드 서버는, 아마존의 어딘가 전산센터에 있는 인프라에 우리가 네트워크로 접근하여 서버를 원격으로 제어하고 사용할 수 있는 것을 말한다. 이런, AWS 로 어떻게 서버가 Deploy 되는지, 간략하게 말로만 설명을 해보겠다. AWS의 많은 서비스 중, EC2라는 기본 서버를 기준으로 설명하겠다. (AWS를 통해 스토리지 장치 등 IT Infra의 많은 것들을 클라우드상에서 생성하고 사용할 수 있지만, 그 중 EC2만 설명하겠다..) EC2는 Elastic Compute Cloud로 독립된 서버(컴퓨터)를 임대해주는 서비스다. [AWS Instance의 개념과 설치] 1. 논리적 서버의 생성: Instance 를 생성하여, 논리적인 하드웨어 ..
1. Array and Linked List? (자료구조 기본_배열과 링크드리스트) 내가 이해하는 컴퓨터 프로그래밍은, 어떤 input 데이터를 넣고, 그것이 생각한 로직대로 Computing 되어 원하는 output을 얻을 수 있도록 코드를 효율적으로 짜는 일이라고 생각한다. 사실, Problem Solving 문제들을 처음 접했을 당시, C++에 있는 STL을 이용하여 이미 구현된 자료구조를 사용했기 때문에 내가 들여쓴 자료구조의 기본 원리에 대해서는 깊게 공부할 필요를 느끼지 못했다.(적어도 C++을 이용한 알고리즘 문제풀이를 놓고 봤을 때) ..이미 너무 구현이 잘되어있더라고.. 이 프로그래밍에서, input 데이터를 '어떻게' 받을지가 중요하다. 문제에 따라 data를 받는 그릇을 최대한 효과적으로 선택해야 효율적으로(시간 복잡도 등을 줄이는 방식으로) 문제를 풀 수 있을 것이..
Circular_Queue(환형 큐) 개념 및 구현 Circular Queue를 알기 위해 Queue부터 먼저 짚고 가자. Queue는 자료구조의 일종으로 어떠한 데이터 집합의 원소들을 Linearly 차례대로 배치한다고 가정했을 때, 선입 선출 방식을 따르는 자료 구조를 의미한다. 이때 Queue는 크기가 정해져있지 않으나,(원소가 큐에 들어가거나 빠질 때마다, Queue의 사이즈가 변하므로..) Circular Queue 개념을 도입하면, Queue의 성질인 선입선출 Rule도 지키면서 Queue의 크기를 고정시킬 수 있다. 아래 그림과 같이, 둥근 환형으로 Queue를 만들고, Queue의 원리대로 원소를 넣고 뺄 수 있는 것이다. 여기서 원소가 들어가는 지점(index)을 Rear, 원소가 빠지는 지점을 Front라고 한다. Circular Que..