프로그래머스146 올바른 괄호 - C++, Stack https://school.programmers.co.kr/learn/courses/30/lessons/12909 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 & 풀이 #include #include #include using namespace std;bool solution(string s){ bool answer = true; stack c_stack; for (char c : s) { if (c == '(') { c_stack.push(c); }else { if (!c_stack.empty()) { .. 2025. 2. 22. 기능 개발 - C++, Queue 주소 코드 & 풀이 vector solution(vector progresses, vector speeds) { vector answer; int day; int max_day = 0; for (int i = 0; i 주석 그대로임 각 작업이 완료되는데 필요한 일수를 계산해서 이를 기반으로 답을 구해갑니다. 현재 최대 일수보다 크다는 것은 지금 완료 되지 않는 다는 것을 뜻하니까, anwer에 새로 추가 현대 최대 일수보다 작거나 같다면 작업이 완료되고 대기하고 있었던 거니까 추가하는 게 아니고 기존의 것에 + 1을 해줍니다. 2025. 2. 22. 최빈값 구하기 - C++, unordered_map, auto 주소 코드 & 풀이 #include #include using namespace std;int solution(vector array) { unordered_map freq; for (int num : array) freq[num]++; int max_cnt = 0, mode = -1; bool is_duplicate = false; for (auto &[num, count] : freq){ if(count > max_cnt){ max_cnt = count; mode = num; is_duplicate = false; } else if(count == max_cnt){ .. 2025. 2. 22. 배열 두 배 만들기 - C++, vector, 참조(&), 반복문 https://school.programmers.co.kr/learn/courses/30/lessons/120809 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 & 풀이 #include using namespace std;vector solution(vector numbers) { for(int &num : numbers){ num 참조(&) 라는 재밌는 방식을 알게 되었다. 예시 5 * 2일 때 5의 이진수 = 0000 0101 10 (5 * 2) 의 이진수 = 0000 1010 이기에 왼쪽으로 한 칸 씩 움직이면( 2배가 되는 것을 볼 수 있습니다. 2025. 2. 22. 억억단을 외우자 - Python https://school.programmers.co.kr/learn/courses/30/lessons/138475 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 & 풀이 def solution(e, starts): num_count = [0] * (e + 1) for i in range(1, int(e ** 0.5) + 1): for j in range(i, e // i + 1): num = i * j if i == j: num_count[num] += 1 else: .. 2025. 2. 21. 부대복귀 - Python, BFS https://school.programmers.co.kr/learn/courses/30/lessons/132266 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 & 풀이 from collections import dequedef solution(n, roads, sources, destination): graph = [[] for _ in range(n + 1)] for start, end in roads: graph[start].append(end) graph[end].append(start) distances = [-1] * (n + 1) .. 2025. 2. 17. 이전 1 2 3 4 5 ··· 25 다음