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) + ...
随机推荐
- 由一个场景分析Mysql的join原理
背景 这几天同事写报表,sql语句如下 select * from `sail_marketing`.`mk_coupon_log` a left join `cp0`.`coupon` c on c ...
- 配置CKFinder(Java版)
1. 下载 CKFinder官网下载地址提供了PHP,ASP, Java等不同下载版本. 2. 配置 1)config.xml放到WEB-INF下, 2)其他文件放到Webcontent下, 3) ...
- Windows系统下如何在cmd命令窗口中切换Python2.7和Python3.6
针对在同一系统下我们可能安装多个版本的Python,毕竟Python2.7与Python3.6还是有不同的需求,但是在用Cmd命令窗口是我们可能默认的系统变量环境是其中一个版本,当我们需要在cmd命令 ...
- 定期删除Azure存储账号下N天之前的数据文件-ASM
######RemoveStorageBlob*DaysOld##### <# .SYNOPSIS Remove all blob contents from one storage accou ...
- leetcode-896-单调数列
题目描述: 如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的. 如果对于所有 i <= j,A[i] ...
- mysql工具——mysqlcheck(MYISAM)
基本介绍 演示: 使用optimize的时候,可能会出现 Table does not support optimize, doing recreate + analyze instead 这时候参考 ...
- PXE+Kickstart 批量安装CentOS 7
安装之前 将需要安装 CentOS 的服务器与 PXE 服务器通过网络设备连接:PXE 服务器安装 CentOS,并且关闭firewalld.selinux,设置静态IP地址,本例设为10.0.0.1 ...
- CountDownLatch的简单实现
1. @Data public abstract class BaseLatch { private int limit; protected int running; BaseLatch(int l ...
- linux下RabbitMQ相关命令
1. 关闭与启动 ① 到指定目录:cd/etc/init.d ② 停止:rabbitmq-server stop ③ 启动:rabbitmq-server start ④ 查看是否停止/启动成功:ps ...
- shiro学习笔记_0400_自定义realm实现身份认证
自定义Realm实现身份认证 先来看下Realm的类继承关系: Realm接口有三个方法,最重要的是第三个方法: a) String getName():返回此realm的名字 b) boolean ...