Given a rectangular matrix of characters, add a border of asterisks(*) to it.
Example
For
picture = ["abc",
"ded"]
the output should be
solution(picture) = ["*****",
"*abc*",
"*ded*",
"*****"]
Input/Output
[execution time limit] 3 seconds (java)
[memory limit] 1 GB
[input] array.string picture
A non-empty array of non-empty equal-length strings.
Guaranteed constraints:
1 ≤ picture.length ≤ 100,
1 ≤ picture[i].length ≤ 100.
[output] array.string
The same matrix of characters, framed with a border of asterisks of width 1.
String[] solution(String[] picture) {
String [] result = new String [picture.length + 2];
int length = picture[0].length() + 2;
String stars = "";
for (int i = 0; i < length; i++) {
stars += "*";
}
result[0] = stars;
result[result.length - 1] = stars;
for (int i = 1; i < result.length - 1; i ++) {
result[i] = "*" + picture[i - 1] + "*";
}
return result;
}