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*",
"*****"]
Input/Output
- [execution time limit] 3 seconds (java)
- [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
- The same matrix of characters, framed with a border of asterisks of width
String[] addBorder(String[] picture) { String startEnd = ""; for(int i = 0; i<picture[0].length()+2;i++){ startEnd +="*"; } ArrayList<String> list = new ArrayList<>(); list.add(startEnd); for(int i = 0; i<picture.length; i++){ list.add("*"+picture[i]+"*"); } list.add(startEnd); return list.toArray(new String[list.size()]); }