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) + ...
随机推荐
- 线程池(Linux实现)
讨论QQ群:135202158 本文技术参考了sourceforge项目c thread pool,链接:http://sourceforge.net/projects/cthpool/ 线程池如上一 ...
- 30 个免费的 Sketch 必备插件
简评:中秋三天小长假,要不要学点啥?比如简单的设计?比如用 Sketch 做个项目? Sketch 有许多值得称赞的地方,其丰富的插件就是亮点之一.Sketch 的社区有着大量免费高效的插件.今天这篇 ...
- 移动端<meta>属性配置讲解(整理)
meta标签,是head区的辅助标签 HTML代码如下: <meta charset="utf-8"><meta http-equiv="X-UA-Co ...
- 架构师养成记--29.redis开篇
主要有从下几点讲解 NOSQL(Redis) 简介.redis安装与部署 Redis基础事件类型详解 Redis高级命令 Redis与java的使用 Redis集群搭建 Redis集群与spring的 ...
- @ModelAttribute注解和POJO传参过程
1.@ModelAttribute注解 @ModelAttribute主要有三个用途,对方法进行注解,对参数进行注解,还有@ModelAttribute和@RequestMapping一起对方法进行注 ...
- opencv 将视频分解成图片和使用本地图片合成视频
代码如下: // cvTest.cpp : Defines the entry point for the console application. #include "stdafx.h&q ...
- ConcurrentHashMap相关知识点
ConcurrentHashMap涉及的知识点:HashMap,HashTable,UnSafe,CAS,数组+链表,Segment,ReentrantLock(非公平锁,公平锁),红黑树. 为什么要 ...
- Android开发不可或缺的十大网站及工具
1. Google 做开发前完全是小白,真心不知道有Google这东西,只晓得百度,遇到问题直接百度,不是黑百度,百度在娱乐八卦方面确实靠谱,但是技术方面查出来的东西基本千篇一律,有些答案甚至还会起到 ...
- (转)DB2和 Oracle的并发控制(锁)比较
DB2和 Oracle的并发控制(锁)比较 牛 新庄2005 年 12 月 26 日发布 原文:https://www.ibm.com/developerworks/cn/data/library/t ...
- 用Akka构建一个简易的分布式文件系统
本来初期打算用Hadoop 2,可是后来有限的服务器部署了Solr Cloud,各种站点,发现资源不够了,近10T的文件,已经几乎把服务器的磁盘全部用光.想来想去,由于目前架构基于Scala的,所以还 ...