본문 바로가기

전체 글

(46)
[알고리즘] LeetCode 746번 "Min Cost Climbing Stairs" (C/C++) - Don 임베디드 문제요약: You are given an integer array cost[] where cost[i] is the cost of ith step on staircase. Once you pay the cost, you can either climb one or two steps from there. You can either start from the step[0] or step[1] Return the minimum cost to reach the top of the floor. 제약: 2
[알고리즘] LeetCode 1번 "Two Sum" (C/C++) - Don 임베디드 문제요약: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. 제약: Each input would have exactly one solution. You cannot use the same element twice. Answer can be in any order. 예제 1 입력. 예제 1 출력. nums = [2,7,11,15], target = 9 [0,1] 예제 2 입력. 예제 2 출력. nums = [3,2,4], target = 6 [1,2] 예제 3 입력. 예제 3 출력. nums = [3,3], target = 6 [0,1] ..
[알고리즘] LeetCode 21번 "Merge Two Sorted Lists" (C/C++) - Don 임베디드 문제요약: Given two heads of sorted linked lists list1 and list2, merge two lists into one sorted linked list and return the head of the merged list. 제약: -100 < Node.val < 100 lists are sorted in non-decreasing order 예제 1 입력. 예제 1 출력. [1,2,4] [1,3,4] [1,1,2,3,4,4] 예제 2 입력. 예제 2 출력. [5] [1,3,4] [1,3,4,5] 정답코드1 (while문 사용): 비교적 복잡하고, 신경써줘야 하는 곳이 많음. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2..
[알고리즘] LeetCode 543번 "Diameter of Binary Tree" (C/C++) - Don 임베디드 문제요약: Given the root of a binary tree, return the length of the "diameter" of the tree. "diameter" of a tree is the length of the longest path between any two nodes in a tree. The path may or may not pass through the root. 제약: number of nodes in range [1, 10^4] -100 right); if ((leftPath + rightPath) > diameter) { diameter = (leftPath + rightPath); } return (leftPath >= rightPath) ? (leftPath + ..
[알고리즘] 백준 7568번 "덩치" (C/C++) - Don 임베디드 문제요약: A의 덩치가 (x1, y1), B의 덩치가 (x2,y2) 이고, x1 > x2 그리고 y1 > y2 를 만족하는 경우 A는 B보다 "덩치가 크다" 라고 표현하기로 하자. x1 > x2 는 만족하지만 y1 y2 는 만족하지만 x1
[알고리즘] 백준 1181번 "단어 정렬" (C/C++) - Don 임베디드 문제요약: 알파벳 소문자로 이루어진 N개의 단어가 주어질 때, 아래 조건으로 정렬하여 출력하는 프로그램을 작성하라. 1. 길이가 짧은 단어부터. 2. 길이가 같으면 사전 순서로. 제약: 제한 시간 2초, 메모리 256MB 1
[알고리즘] 백준 18258번 "큐 2" (C/C++) - Don 임베디드 문제요약: 정수를 저장하는 Queue를 구현하고, 다음 입력에 대한 동작을 구현하라. - Push X : 정수 X를 큐에 넣는 연산. - Pop : 큐에서 가장 앞에 있는 정수를 빼고, 그 수를 출력. - Size : 큐에 들어있는 정수의 개수를 출력. - Empty : 큐가 비어있으면 1, 아니면 0을 출력. - Front : 큐의 가장 앞에있는 정수를 출력. 빈 경우 -1 출력. - Back : 큐의 가장 뒤에 있는 정수를 출력. 빈 경우 -1 출력. 제약: 시간 제한 1초, 메모리 제한 512MB, 명령의 수 N, 1pNextNode = pobjNode; pBackNode = pobjNode; } nCount++; } void List::Pop(void) { if (nCount == 0) { pri..
[알고리즘] 백준 11651번 "좌표 정렬하기 2" (C/C++) - Don 임베디드 문제요약: 2차원 평면상의 점 N개의 좌표가 주어졌을때, N개의 점을 Y 좌표가 증가하는 순으로, Y 좌표가 같으면 X 좌표가 증가하는 순서로 정렬하여 출력하는 프로그램을 작성하라. 제약: 시간 제약 1초, 메모리 256MB 1 > nTmpY; v.push_back(Point(nTmpX, nTmpY)); } // compare 함수를 사용하여 입력된 좌표들을 정렬. sort(v.begin(), v.end(), compare); vector ::iterator iter; for (iter = v.begin(); iter