Data Structure & Algorithms47 [DS] Cheating sheet 정리 다시 오랜만에 자료구조를 공부할려고 하니 머리가 지끈하다.. 그리하여 인프런에서 c++ 코테(큰돌)를 결제를 질러버렸다. 하하 우선 릿코드로 자료구조를 한바퀴 돌렸고 여기서 제공해준 템플릿좀 정리해볼려한다. array쪽은 한번 올렸고 나머지인 linked list , stack , dfs, bfs, graph, binery search, backtracking 식으로 정리. Linked list: fast and slow pointer int fn(ListNode* head) { ListNode* slow = head; ListNode* fast = head; int ans = 0; while (fast != nullptr && fast->next != nullptr) { // do logic slow .. 2023. 4. 26. [Queues] queue 개념 잡기 2 (stack ,heap, queue의 관계) 오랜만에 하니까 헷갈리니 다시 정리좀 해볼려고한다. 그전에 너무 대충 정리했네 ㅎㅎ.. 메모리 관점과 데이터 구조 관점에서 바라보기. stack 과 queue는 쌍쌍바같은 존재인데 이게 heap이라는 녀석과 헷갈렸다. 이는 내가 데이터 구조와 컴퓨터 아키텍쳐에서 메모리 부분을 정확하게 알지못해서 발생하는것이다. stack 이란 메모리 관점과 데이터구조 관점 두가지에서 사용되는데 (동음이의어) 데이터 구조는 메모리를 가지고 구조화한것으로 이미 만들어져 있는게 아니라 사람들이 임의로 룰을 정해서 데이터를 관리하는것이라 생각하면된다. 1) 데이터 구조로 보면 하나의 컨테이너로 언제든 추가가 가능한 어레이(혹은 linked list) 구조이지만 가장 최근에 추가 혹은 제거가 되는 룰 구조이다. 2) 메모리 뷰 .. 2023. 3. 24. [linked list] 92. Reverse Linked List II https://leetcode.com/problems/reverse-linked-list-ii/description/ Reverse Linked List II - LeetCode Can you solve this real interview question? Reverse Linked List II - Given the head of a singly linked list and two integers left and right where left 30 Step-4 : Curr will point to 5 i.e. 10 --> 5 forw will point to just after prev i.e. 40 --> 30 pre will point to forw i.e. 2 --> 40 Now, ladies-n.. 2023. 3. 23. [Hashing] 2260. Minimum Consecutive Cards to Pick Up https://leetcode.com/problems/minimum-consecutive-cards-to-pick-up/ Minimum Consecutive Cards to Pick Up - LeetCode Can you solve this real interview question? Minimum Consecutive Cards to Pick Up - You are given an integer array cards where cards[i] represents the value of the ith card. A pair of cards are matching if the cards have the same value. Return the minimum n leetcode.com 난이도: medium .. 2023. 3. 17. [Hashing] 해쉬를 핵심만 정리해보자 해쉬 테이블 (hash table) key,value 로 데이터를 저장하는 자료구조 , 정말빠르게 O(1)으로 자료를 검색할 수 있는 기적의 구조 (어떻게 검색을하길래?) 내부적으로 배열(버킷) 을 사용하여 데이터를 저장해서. 해쉬 함수는 고유의 KEY값에 따라 Value(bucket)에 전달해주는데 이를 이용해 암호학(내부 해쉬 함수가 어떻게 생긴지 모르니 밖에서는 고유 key값으로만 내부에 접근할수있는 원리) 에도 사용!! 근데 만약 두개 다른 key가 같은 value를 지칭하게 된다면? -> 충돌. 이를 해결하기위해 체이닝(chaining기법을 사용) 체이닝의 장점: 1. 탐색 저장 삭제시 연결리스트(linked list)에서 독립적으로 수행 -> 오버플로우가 발생해도 시간이 효율적 2. 연결 리스.. 2023. 3. 12. [Array and String] Prefix sum 개념 릿코드로 이번 챕터를 정주행중인데 Rrefix sum 알고리즘에 대한것은 이 블로그에서 잘 정리한듯. 핵심이 팍온다. => sum을 어레이 형태로 저장해놔서 필요에 따라 바로 바로 쓸수있도록. https://www.crocus.co.kr/843 구간 합(Prefix Sum) 알고리즘 목차 1. 구간 합(Prefix Sum)이란? 2. 구간 합(Prefix Sum)이 어디에 쓰일까? 3. Prefix Sum Algorithm 4. Prefix Sum이 쓰이는 문제들 1. 구간 합(Prefix Sum)이란? 공부를 하다보면 부분 합, 구간 합의 개념이 헷갈릴 때 www.crocus.co.kr 릿코드에서 제시한 예제 문제 (어려운데..?) https://leetcode.com/problems/number-of.. 2023. 3. 9. [Array]643. Maximum Average Subarray I https://leetcode.com/problems/maximum-average-subarray-i/description/ Maximum Average Subarray I - LeetCode Can you solve this real interview question? Maximum Average Subarray I - You are given an integer array nums consisting of n elements, and an integer k. Find a contiguous subarray whose length is equal to k that has the maximum average value and return thi leetcode.com Code template: 3. sl.. 2023. 3. 7. [Arrrays and String] 713. Subarray Product Less Than K (투포인트와 슬라이딩 윈도우 개념 헷갈림) https://leetcode.com/problems/subarray-product-less-than-k/ Subarray Product Less Than K - LeetCode Can you solve this real interview question? Subarray Product Less Than K - Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k. Example leetcode.com 코드 템플릿 : 3. Sliding window( can.. 2023. 3. 3. 이전 1 2 3 4 ··· 6 다음