본문 바로가기
반응형
[PCCP] Lv1: 카드 뭉치(159994) 해설 문제- 문제 링크: 카드 뭉치 해설- 자료구조: - 시간복잡도:  (풀이과정)1) goal의 front와 cards1의 front 또는 goal의 front와 cards2의 front를 비교1-1) 사용할 수 있는 카드가 있다면 해당 큐와 goal에서 pop을 수행 1-2) 사용할 수 있는 카드가 있다면 동작하지 않음 1-3) cards1, cards2 중 빈곳은 테크하지 않음  코드(C언어)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: cards1과 cards2의 길이- M: goal의 길이- cards1와 cards2, goal을 큐로 변환하기 위한 시간 복잡도는 O(N + M)- 반복문에서.. 2024. 12. 24.
[PCCP] Lv2: 기능개발(42586) 해설 문제- 문제 링크: 기능개발 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 각 작업의 배포 가능일 구하기2) 배포 가능일이 첫번째 작업일보다 빠르면 동시에 배포3) 첫번째 작업일보다 늦은 작업일이 존재한다면 2번과정과 유사하게 해당 작업일 이후의 작업들을 묶어서 배포4) 위의 과정 반복 코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: progresses의 길이- day_left 벡터를 생성하기 위한 시간 복잡도: O(N)- day_left의 각 요소를 한 번씩 순회할 때의 시간 복잡도: O(N)- 최종 시간 복잡도: O(N)더보기#include #include .. 2024. 12. 24.
[PCCP] Lv3: 표 편집(81303) 해설 문제- 문제 링크: 표 편집 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: 표의 행 길이- 벡터를 초기화할 때 시간 복잡도는 O(N)- 제약사항을 보면 명령어 뒤의 X의 모든 합이 100만을 넘지 않으므로 명령어 처리시 시간복잡도는 O(1,000,000)_- 최종 시간 복잡도: O(N)더보기#include #include #include using namespace std;string solution(int n, int k, vector cmd) { // 삭제된 행의 인덱스 저장 sta.. 2024. 12. 24.
[PCCP] Lv1: 크레인 인형 뽑기 게임(64061) 해설 문제- 문제 링크: 크레인 인형 뽑기 게임 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: board의 행 혹은 열의 길이- M: moves의 길이- board를 순회하는 과정은 O(N^2)- moves를 순회하는 과정은 O(M)- 총 시간 복잡도: O(N^2 + M)더보기#include #include using namespace std;int solution(vector> board, vector moves) { // 보드 열 크기만큼 스택 생성 stack lanes[board[0]... 2024. 12. 24.
[PCCP] Lv2: 주식 가격(42584) 해설 문제- 문제 링크: 주식 가격 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: prices의 길이- 최악의 경우 각 prices의 원소들은 한 번씩 푸시/팝하므로 시간 복잡도는 O(N)더보기#include #include #include using namespace std;vector solution(vector prices) { // 가격이 떨어지지 않은 기간을 저장한 벡터 vector answer(prices.size()); // 스택에는 prices의 인덱스가 들어감. 이전 가.. 2024. 12. 24.
[PCCP] Lv2: 짝지어 제거하기(12973) 해설 문제- 문제 링크: 짝지어 제거하기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: s의 길이- 문자열의 모든 문자를 한 번씩 순회하므로 시간 복잡도는 O(N)더보기#include #include using namespace std;int solution(string s) { stack st; for (int i = 0; i solution 2)더보기#include #include #include using namespace std;int solution(string s){ .. 2024. 12. 24.
[PCCP] Lv2: 괄호 회전하기(76502) 해설 문제- 문제 링크: 괄호 회전하기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: s의 길이- 각 문자열을 순회하면 N개의 케이스가 생기고 각 문자열마다 올바른 괄호 여부를 체크하므로 시간 복잡도는 O(N^2)더보기#include #include #include #include using namespace std;// 닫힌 괄호의 짝을 바로 확인할 수 있도록 맵 선언unordered_map bracketPair = {{')', '('}, {']', '['}, {'}', '{'}};// 인수로 받은 문자열.. 2024. 12. 24.
[PCCP] Lv2: N^2 배열자르기(87390) 해설 문제- 문제 링크: 배열자르기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#include #include #include int* solution(int n, long long left, long long right) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(sizeof(int)*(right-left+1)); int quo = 0; int rem = 0; for (long long i = 0; i = rem) answer[i] = quo + 1; .. 2024. 12. 23.
[PCCP] Lv0: 배열의 평균값(120817) 해설 문제- 문제 링크: 배열의 평균값 해설- 자료구조: - 시간복잡도: (풀이과정) 1) 배열의 합을 구함2) 배열의 길이를 구함3) 배열의 합을 배열의 길이로 나누어 결과에 저장4) 결과 반환 코드(C언어)더보기#include #include #include // numbers_len은 배열 numbers의 길이입니다.double solution(int numbers[], size_t numbers_len) { double answer = 0; double sum = 0; for (int i = 0; i  (C++)더보기#include #include using namespace std;double solution(vector numbers) { double answer = 0.. 2024. 12. 23.
[PCCP] Lv2: 방문 길이(49994) 해설 문제- 문제 링크: 방문 길이 해설- 자료구조: - 시간복잡도:  (풀이과정)- 중복 경로 처리- 음수 좌표 처리- 기능별 함수 구현1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: dirs의 길이- dirs의 길이만큼 순회: O(N)더보기#include using namespace std;// 특정 좌표에서 특정 방향으로 이동한 적이 있는지 체크bool visited[11][11][4];// 상하좌우로 좌표를 이동할 때 필요한 좌표 오프셋 배열int dx[] = {0, 1, 0, -1};int dy[] = {-1, 0, 1, 0};// 각 문자.. 2024. 12. 23.
반응형