[풀이 - Beautiful Pairs] : <Easy / 75.21%>
더보기
int beautifulPairs(vector<int> A, vector<int> B)
{
int result = 0;
//
for(int i = 0; i < A.size(); ++i)
{
if(B.empty() == true)
break;
//
auto iter = B.begin(), end = B.end();
for(; iter != end; ++iter)
{
if(*iter == A[i])
{
B.erase(iter);
++result;
break;
}
}
}
//
if(B.size() > 0)
++result;
else if(result == A.size())
--result;
//
return result;
}
# Think Point : pair 갯수가 N일 때 결과값에 1을 빼준다 (Your task is to change exactly 1 element in B)
[풀이 - Sherlock and The Beast] : <Easy / 82.14%>
더보기
void decentNumber(int n)
{
int five = n, three = 0;
while(five >= 0)
{
if(five % 3 == 0 && three % 5 == 0)
break;
else
--five, ++three;
}
//
if(five < 0)
{
cout << -1 << endl;
return;
}
else
{
string result = "";
for(int i = 0; i < five; ++i)
result += '5';
for(int i = 0; i < three; ++i)
result += '3';
//
cout << result << endl;
}
}
[풀이 - Priyanka and Toys] : <Easy / 91.06%>
더보기
int toys(vector<int> w)
{
int result = 0, minWeight = 0;
//
sort(w.begin(), w.end());
// Set First Ship
++result;
minWeight = w[0];
//
int count = w.size();
for(int i = 1; i < count; ++i)
{
// Check is need another ship
if(w[i] > minWeight + 4)
{
minWeight = w[i];
++result;
}
}
//
return result;
}
[풀이 - Largest Permutation] : <Easy / 60.81%>
더보기
vector<int> largestPermutation(int k, vector<int> arr)
{
int count = arr.size();
int max = count, pos = 0;
//
while(k > 0)
{
--k;
//
for(int i = pos; i < count; ++i)
{
if(arr[i] == max)
{
if(i != pos)
{
Swap(arr, pos, i);
++pos, --max;
break;
}
else
{
++pos, --max;
continue;
}
}
}
}
//
return arr;
}