본문 바로가기
반응형

전체 글222

[프로그래머스 - 그래프] 가장 먼 노드 카테고리 게시글 작성 날짜 게시글 최근 수정 날짜 작성자 Algorithm 2019-04-05 22:00 2022.02.25. 01:23 Dev.Yang n개의 노드가 있는 그래프가 있습니다. 각 노드는 1부터 n까지 번호가 적혀있습니다. 1번 노드에서 가장 멀리 떨어진 노드의 갯수를 구하려고 합니다. 가장 멀리 떨어진 노드란 최단경로로 이동했을 때 간선의 개수가 가장 많은 노드들을 의미합니다. 노드의 개수 n, 간선에 대한 정보가 담긴 2차원 배열 vertex가 매개변수로 주어질 때, 1번 노드로부터 가장 멀리 떨어진 노드가 몇 개인지를 return 하도록 solution 함수를 작성해주세요. [제한사항] 노드의 개수 n은 2 이상 20,000 이하입니다. 간선은 양방향이며 총 1개 이상 50,000개.. 2019. 4. 5.
[프로그래머스 - 완전탐색] 숫자 야구 📄 [완전탐색] 숫자 야구 C++ Source Code #include #include #include #include using namespace std; #define INT_PAIR pair #define CUS_PAIR pair #define START 123 #define END 987 const bool findDigit(const INT_PAIR condition, const string target, const string match) { INT_PAIR conds = make_pair(0, 0); for (int ii = 0; ii < target.size(); ii++) { for (int jj = 0; jj < match.size(); jj++) { // Case Find Strike.. 2019. 4. 5.
[프로그래머스 - 정렬] K번째수 📄 [정렬] K번째수 C++ Source Code #include #include #include using namespace std; const int findTarget(const vector & arr, const int left, const int right, const int target) { vector bucket = vector(arr.begin() + left, arr.begin() + right); std::sort(bucket.begin(), bucket.end()); return bucket[target]; } vector solution(vector array, vector commands) { vector answer; for (const auto command : command.. 2019. 4. 5.
[프로그래머스 - 정렬] H-Index 📄 [정렬] H-Index Swift Source Code import Foundation // MARK: - https://en.wikipedia.org/wiki/H-index func solution(_ citations:[Int]) -> Int { let length = citations.count // MARK: - First we order the values of f from the largest to the lowest value. (DESC - 오름차순) let paper = citations.sorted { $0 > $1 } // MARK: - we look for the last position in which f is greater than or equal to the position.. 2019. 4. 5.
반응형