728x90
반응형
문제: 해커랭크 - Counting Sort 1,2
www.hackerrank.com/challenges/countingsort1/problem
언어 : C++
Counter Sort 1
// Complete the countingSort function below.
vector<int> countingSort(vector<int> arr) {
vector<int> counter(100);
for(int i = 0 ;i<arr.size(); i++)
{
counter[arr[i]] ++;
}
return counter;
}
Counter Sort 2
// Complete the countingSort function below.
vector<int> countingSort(vector<int> arr) {
vector<int> counter(100);
vector<int> sorted;
for(int i = 0 ;i<arr.size(); i++)
{
counter[arr[i]] ++;
}
for(int i = 0 ;i<100; i++)
{
for(int j = 0;j<counter[i];j++)
{
sorted.push_back(i);
}
}
return sorted;
}
728x90
반응형
'개발 > 코딩' 카테고리의 다른 글
해커랭크(HackerRank) - Closest Numbers / C++ (0) | 2020.07.11 |
---|---|
해커랭크(HackerRank) - The Full Counting Sort / C++ (0) | 2020.07.11 |
해커랭크(HackerRank) - Running Time of Algorithms / C++ (0) | 2020.07.11 |
재귀(Recusion) 알고리즘 사용 예 (1) | 2020.07.10 |
해커랭크(HackerRank) - Strong Password / C++ (0) | 2020.06.30 |
댓글