python编程 给一个大于等于0的整数n,创建一个有以下规律,长度为n*n的数列.n=3 :{0,0,1,0,2,1,3,2,1} (空格只是说这里有三组)square_up(3) → [0,0,1,0,2,1,3,2,1]square_up(2) → [0,1,2,1]square_up(4) → [0,0,0,1,0,0,2
来源:学生作业帮助网 编辑:作业帮 时间:2024/09/06 10:25:22
![python编程 给一个大于等于0的整数n,创建一个有以下规律,长度为n*n的数列.n=3 :{0,0,1,0,2,1,3,2,1} (空格只是说这里有三组)square_up(3) → [0,0,1,0,2,1,3,2,1]square_up(2) → [0,1,2,1]square_up(4) → [0,0,0,1,0,0,2](/uploads/image/z/4089625-25-5.jpg?t=python%E7%BC%96%E7%A8%8B+%E7%BB%99%E4%B8%80%E4%B8%AA%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E0%E7%9A%84%E6%95%B4%E6%95%B0n%2C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%9C%89%E4%BB%A5%E4%B8%8B%E8%A7%84%E5%BE%8B%2C%E9%95%BF%E5%BA%A6%E4%B8%BAn%2An%E7%9A%84%E6%95%B0%E5%88%97.n%3D3+%3A%7B0%2C0%2C1%2C0%2C2%2C1%2C3%2C2%2C1%7D+%EF%BC%88%E7%A9%BA%E6%A0%BC%E5%8F%AA%E6%98%AF%E8%AF%B4%E8%BF%99%E9%87%8C%E6%9C%89%E4%B8%89%E7%BB%84%EF%BC%89square_up%283%29+%E2%86%92+%5B0%2C0%2C1%2C0%2C2%2C1%2C3%2C2%2C1%5Dsquare_up%282%29+%E2%86%92+%5B0%2C1%2C2%2C1%5Dsquare_up%284%29+%E2%86%92+%5B0%2C0%2C0%2C1%2C0%2C0%2C2)
python编程 给一个大于等于0的整数n,创建一个有以下规律,长度为n*n的数列.n=3 :{0,0,1,0,2,1,3,2,1} (空格只是说这里有三组)square_up(3) → [0,0,1,0,2,1,3,2,1]square_up(2) → [0,1,2,1]square_up(4) → [0,0,0,1,0,0,2
python编程 给一个大于等于0的整数n,创建一个有以下规律,长度为n*n的数列.
n=3 :{0,0,1,0,2,1,3,2,1} (空格只是说这里有三组)
square_up(3) → [0,0,1,0,2,1,3,2,1]
square_up(2) → [0,1,2,1]
square_up(4) → [0,0,0,1,0,0,2,1,0,3,2,1,4,3,2,1]
def square_up(n):
关于我下面追加提问的镜面问题我这边有所有的例子
max_mirror([21,22,9,8,7,6,23,24,6,7,8,9,25,7,8,9 ]) → 4
max_mirror([1,2,1,20,21,1,2,1,2,23,24,2,1,2,1,25]) → 4
max_mirror([1,2,3,2,1]) → 5
max_mirror([1,2,3,3,8]) → 2
max_mirror([1,2,7,8,1,7,2]) → 2
max_mirror([1,1,1]) → 3
max_mirror([1]) → 1
max_mirror([]) → 0
max_mirror([9,1,1,4,2,1,1,1]) → 3 懂英文的可以看原题
We'll say that a "mirror" section in an array is a group of contiguous elements such that somewhere in the array,the same group appears in reverse order.For example,the largest mirror section in {1,2,3,8,9,3,2,1} is length 3 (the {1,2,3} part).Return the size of the largest mirror section found in the given array.
python编程 给一个大于等于0的整数n,创建一个有以下规律,长度为n*n的数列.n=3 :{0,0,1,0,2,1,3,2,1} (空格只是说这里有三组)square_up(3) → [0,0,1,0,2,1,3,2,1]square_up(2) → [0,1,2,1]square_up(4) → [0,0,0,1,0,0,2
def square_up(n):
L = []
for i in [[0] * (n - i) + list(range(i,0,-1)) for i in range(1,n + 1)]:
L += i
return L
其中列表表达式生成的是形如[[0,1],[2,1]]这样的序列,接下来的步骤是去掉中括号.