NP61. 牛牛的矩阵相加
描述
输入描述
输出描述
示例1
输入:
2
输出:
[[2, 4, 6], [8, 10, 12], [14, 16, 18]]
Python 解法, 执行用时: 11ms, 内存消耗: 3084KB, 提交时间: 2022-08-01
my_list = [ [1,2,3], [4,5,6], [7,8,9] ] n = int(input()) for i in my_list: for j in range(len(i)): i[j] = i[j] * n print(my_list)
Python 解法, 执行用时: 12ms, 内存消耗: 3016KB, 提交时间: 2022-07-30
my_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] res_list = list() res = list() n = int(input()) for list_ in my_list: for item in list_: res_list.append(item * n) res.append(res_list) res_list = list() print(res)
Python 解法, 执行用时: 12ms, 内存消耗: 3176KB, 提交时间: 2022-08-01
list = my_list = [ [1,2,3], [4,5,6], [7,8,9] ] n = int(input()) for i in list: for j in range(len(i)): i[j] = i[j] * n print(list)
Python 解法, 执行用时: 14ms, 内存消耗: 3092KB, 提交时间: 2022-08-04
a=[[1,2,3],[4,5,6],[7,8,9]] n= int(input()) for i in range(len(a)): for j in range(len(a[i])): a[i][j]= a[i][j]*n print(a)
Python 解法, 执行用时: 15ms, 内存消耗: 2944KB, 提交时间: 2022-07-29
list1 = [1,2,3] list2 = [4,5,6] list3 = [7,8,9] n = int(input()) list4 = [[x*n for x in list1], [y*n for y in list2], [z*n for z in list3]] print(list4)