Code Signal_练习题_Add Border
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*",
"*****"]
永远都是最笨的方法........
def addBorder(picture):
for i in range(len(picture)):
picture[i] = '*'+picture[i]+'*'
picture.insert(0,'*'*(len(picture[0])))
picture.append('*'*(len(picture[0])))
return picture
膜拜大佬:
def addBorder(picture):
l=len(picture[0])+2
return ["*"*l]+[x.center(l,"*") for x in picture]+["*"*l]
Code Signal_练习题_Add Border的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- Code Signal_练习题_absoluteValuesSumMinimization
Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...
随机推荐
- C语言实现单链表,并完成链表常用API函数
C语言实现单链表,并完成链表常用API函数: 1.链表增.删.改.查. 2.打印链表.反转打印.打印环形链表. 3.链表排序.链表冒泡排序.链表快速排序. 4.求链表节点个数(普通方法.递归方法). ...
- oracle中将number类型毫秒值转为时间类型
在搞数据库时,发现有这样的一个字段,类型是NUMBER(38),查看了一下里面的数据,都是这样的: 13239576781141321326994295132212930680413221297162 ...
- leetcode-383-Ransom Note(以空间换时间)
题目描述: Given an arbitrary ransom note string and another string containing letters from all the magaz ...
- 【性能测试】:LR插入mysql数据库数据,脚本参数化问题
一,今天准备脚本做mysql数据库的铺地数据,脚本内容不赘述,在批量执行insert语句时候,出现一个问题: // sprintf(chQuery, "insert into table ( ...
- mysql数据库使用脚本实现分库备份过程
一条命令解决分库分表备份: [root@db01 data]# mysql -uroot -p123456 -e "show databases;"|egrep -v " ...
- c#Task类。实现异步的一种方式
Task和Task<TResult>是c#提供的一种实现异步功能的2个类.Task<TResult>继承Task类,有返回参数. 1.基本用法 不嵌套利用静态方法创建和运行任务 ...
- PHP-GD库开发手记
创建带有alpha通道的背景输出图像画中文字体获取长宽等比例缩放图片,也可以用于裁切实例代码 创建带有alpha通道的背景 $png = imagecreatetruecolor(800, 600); ...
- Linus' Law
Given enough eyeballs, all bugs are shallow. ------埃里克 ...
- 第一个hibernate程序HelloWorldHibernate
HelloWorldHibernate步骤: HelloWorld 1,新建java项目hibernate_0100_HelloWorld 2,学习User-library-hibernate,并加入 ...
- Linux常用命令之sed(2)
Sed SED的英文全称是 Stream EDitor,它是一个简单而强大的文本解析转换工具,在1973-1974年期间由贝尔实验室的Lee E. McMahon开发,今天,它已经运行在所有的主流操作 ...