Problem


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

  • [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.



Solution

def addBoarder(picture):

lst = []


lst.append("*" * len(picture[0] + 2))

for i in picture:

i = "*" + i + "*"

lst.append(i)

lst.append("*" * len(picture[0] + 2))


return lst


*lst : 애스터리스크(*)를 포함하여 저장할 리스트 변수입니다.

'Programming > Algorithm' 카테고리의 다른 글

[Algorithm] arrayChange  (0) 2018.02.26
[Algorithm] areSimilar  (0) 2018.02.26
[Algorithm] alternatingSums  (0) 2018.02.26
[Algorithm] reverseParentheses  (0) 2018.02.20
[Algorithm] sortByHeight  (0) 2018.02.09

+ Recent posts