전체 글 - Table of Contents331

🥪Array 1. Fundamentals★ Stores items(C/C++) or their references(Python) at contiguous locations / a linear data structure that stores similar elements in contiguous memory locations. ★(1) Random Access: i-th item can be accessed in O(1) Time as we have the base address and every item or reference is of same size(2) Cache Friendliness: since items/references are stored at contiguous locations, we get th.. Computer Science/Data Structures 2025. 1. 17.
★Topology Sort Advanced - 2 Solved★ ★ 2252 줄 세우기 ★import sysinput=sys.stdin.readlinefrom collections import dequeN,M=map(int,input().split())indegree = [0] * (N+1)graph = [[] for _ in range(N+1)]for _ in range(M): A,B=map(int,input().split()) graph[A].append(B) indegree[B] += 1result = []queue = deque()#1for i in range(1,N+1): if indegree[i] == 0: queue.append(i)#2while queue: node = queue.popleft() result.. BOJ/🥇 2024. 12. 29.
🧑🏻‍💻 LeetCode Medium Collections 3 - 19 Problems 0003. Longest Substring Without Repeating Characters / 0221. Maximal Square#---------------- (1)class Solution: def lengthOfLongestSubstring(self, s: str) -> int: ans = 0 hashmap = dict() for i in range(len(s)): if s[i] in hashmap.keys(): needs_to_be_deleted_keys = set() for key in hashmap: if hashmap[key] int: .. LeetCode Problems/Medium 2024. 12. 9.
(C++) ★Binary Search Intermediate I - 1 Solved★ ★ 1920 수 찾기 ★//1920#include #include #include #include #include #include #include #include #include #include using namespace std;int binary_search(vector &arr, int target){ int start, end; start = 0; end = arr.size()-1; int mid; while(start> N; vector arr1(N); for(int i=0;i> x; arr1[i]=x; } cin >> M; vector arr2(M); for(int i=0;i> y; arr2[i]=y; }.. C, C++/🥈 BOJ 2024. 11. 15.
(C++) ★DP Upper-Intermediate I - 2 Solved★ ★ 2579 계단 오르기 ★//2579#include #include #include #include #include #include #include #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, stair,tmp; cin >> N; tmp = N; vector dp(N+1, 0); vector stairs = {0}; while(tmp--){ cin >> stair; stairs.push_back(stair); } dp[1]=stai.. C, C++/🥈 BOJ 2024. 11. 15.
(C++) ★Backtracking Intermediate I - 3 Solved★ ★ 15649 N과 M (1) ★//15649#include #include #include #include #include #include #include #include #include #include using namespace std;int N,M;vector ans;void track(){ if((int)ans.size()==M){ for(int i=0;i> N >> M; track(); return 0;}🙃 track() 백트래킹 재귀 함수 돌리기(1) 조건 충족 시, 충족된 vector 배열 내용 출력(2) 조건 미충족 시, 1부터 N까지의 자연수 일일이 돌리면서 ans 배열이 비었거나 해당 자연수가 ans 배열에 없거나 두 조건 중 한 개를 충족하면 push_bac.. C, C++/🥈 BOJ 2024. 11. 15.
(C++) ★Set/Map Upper-Intermediate I - 1 Solved★ ★ 20920 영단어 암기는 괴로워 ★//20920#include #include #include #include #include #include #include #include #include #include using namespace std;int N,M;string word;map freq;vector vocas;bool compare(string a, string b){ if(freq[a] != freq[b]){ return freq[a] > freq[b]; } else{ if(a.size() != b.size()){ return a.size() > b.size(); } else{ retur.. C, C++/🥈 BOJ 2024. 11. 15.
(C++) ★Stack & Queue & Deque Intermediate I - 4 Solved★ ★ 28278 스택 2 ★//28278#include #include #include #include #include #include #include #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, order, num; cin >> N; stack s; while(N--){ cin>>order; if (order==1){ cin>>num; s.push(num); } else if(orde.. C, C++/🥈 BOJ 2024. 11. 15.
(C++) ★Number Theory Intermediate I - 2 Solved★ ★ 1929 소수 구하기 ★//1929#include #include #include #include #include #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int M, N; cin >> M >> N; vector sieve(N+1, true); for(int i=2;i👳🏻‍♀️ vector sieve 가변 배열을 만든다. (N+1, true)를 뒤에 붙이면 총 N+1개의 자리가 있고 모두 true로 initialization. 👳🏻‍♀️자연수 N까지의 모든 소수 구하기 (에라토.. C, C++/🥈 BOJ 2024. 11. 15.
(C++) ★Set/Map Intermediate I - 5 Solved★ ★ 10815 숫자 카드 ★//10815#include #include #include #include #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N,M,card,judge; vector cards; vector judges; map Map; cin >> N; while(N--){ cin >> card; Map.insert({card, true}); } cin >> M; while(M--){ cin >> judge; .. C, C++/🥈 BOJ 2024. 11. 14.
(C++) ★Sorting Intermediate I - 5 Solved★ ★ 1427 소트인사이드 ★//1427#include #include #include #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string N; cin >> N; sort(N.begin(), N.end(), greater()); cout  🚀 내림차순은 sort()의 세번째 인자에 greater를 넣는다. 이 때, 문자열의 각 문자를 내림차순으로 정렬한다면 greater. 만약에 int형 변수가 들어간 array를 내림차순 정렬한다면 greater를 sort()의 세번째 인자로 넣는다... C, C++/🥈 BOJ 2024. 11. 14.
(C++)★Sorting Upper-Beginner I - 1 Solved★ ★ 2750 수 정렬하기 ★//1436#include #include #include #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; vector arr{}; while(N--){ int x; cin >> x; arr.push_back(x); } sort(arr.begin(),arr.end()); for(int x=0;x 👯‍♂️ vector arr{}로 가변 배열 만들고 push_back()으로 업데이트. 이.. C, C++/🥉 BOJ 2024. 11. 14.