반응형
Given a rectangular matrix of characters, add a border of asterisks(*) to it. Example For picture = ["abc", "ded"] the output should be addBorder(picture) = ["*****", "*abc*", "*ded*", "*****"] |
code>>
std::vector<std::string> addBorder(std::vector<std::string> picture) {
for (int i = 0; i < picture.size(); i++)
{
picture[i] = "*" + picture[i] + "*";
}
picture.insert(picture.begin(), std::string(picture[0].size(), '*'));
picture.insert(picture.end(), std::string(picture[0].size(), '*'));
return picture;
}
반응형
'알고리즘 > codefights' 카테고리의 다른 글
17>arrayChange (0) | 2017.07.01 |
---|---|
16>areSimilar (0) | 2017.06.28 |
14>alternatingSums (0) | 2017.06.28 |
13>reverseParentheses (0) | 2017.06.28 |
12>sortByHeight (0) | 2017.06.28 |