描述
输入一个正整数N, 你需要按如下方式返回一个字符串列表。
样例
样例 1:
输入:1
输出:
[
"X"
]
样例 2:
输入:2
输出:
[
"XX",
"XX"
]
样例 3:
输入:3
输出:
[
"X X",
" X ",
"X X"
]
样例 4:
输入:4
输出:
[
"X X",
" XX ",
" XX ",
"X X"
]
样例 5:
输入:5
输出:
[
"X X",
" X X ",
" X ",
" X X ",
"X X"
]
class Solution:
"""
@param n: An integer.
@return: A string list.
"""
def printX(self, n):
res = []
for i in range(n//2):
res.append(" "*i + "X" + " "*(n-2*i-2) + "X" + " "*i)
if n%2==1:
res.append(" "*(n//2) + "X" +" "*(n//2))
res.extend(res[:n//2][::-1])
return res
原文:https://www.cnblogs.com/bernieloveslife/p/14634866.html