Code Signal_练习题_All Longest Strings
Given an array of strings, return another array containing all of its longest strings.
Example
For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should beallLongestStrings(inputArray) = ["aba", "vcd", "aba"].
Input/Output
[execution time limit] 4 seconds (py3)
[input] array.string inputArray
A non-empty array.
Guaranteed constraints:
1 ≤ inputArray.length ≤ 10,1 ≤ inputArray[i].length ≤ 10.[output] array.string
Array of the longest strings, stored in the same order as in the
inputArray.
我的解答:
def allLongestStrings(inputArray):
li = []
m = max(inputArray,key=len)
for i in inputArray:
if len(i) == len(m):
li.append(i)
return li
膜拜大佬:
def allLongestStrings(inputArray):
m = max(len(s) for s in inputArray)
r = [s for s in inputArray if len(s) == m]
return r
虽然代码比大佬写的多,但至少想法一样了....
Code Signal_练习题_All Longest Strings的更多相关文章
- 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_练习题_reverseParentheses
You have a string s that consists of English letters, punctuation marks, whitespace characters, and ...
- Code Signal_练习题_commonCharacterCount
Given two strings, find the number of common characters between them. Example For s1 = "aabcc&q ...
- 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 ...
随机推荐
- Python小白学习之路(十七)—【内置函数二】
序列操作类函数 all() 功能:判断可迭代对象的每个元素是否都为True值注意:If the iterable is empty, return True.(举例3) 回顾:None '' ...
- Oracle sys或者system的默认密码
Oracle的sys和system默认密码 system默认:manager sys默认:change_on_install 使用SQL Plus登录数据库时,system使用密码manager可 ...
- Karatsuba乘法--实现大数相乘
Karatsuba乘法 Karatsuba乘法是一种快速乘法.此算法在1960年由Anatolii Alexeevitch Karatsuba 提出,并于1962年得以发表.此算法主要用于两个大数相乘 ...
- heroku 部署ruby项目后 未连接数据库显示(We're sorry, but something went wrong. If you are the application owner )
如何部署请参照: http://blog.csdn.net/xz360717118/article/details/62422741 部署后如果发现显示:We're sorry, but someth ...
- netsh 第一次用这命令
转载自 目标是WIN7 X64,且开启了防火墙,想要用他的机器去访问别的机器,又不想登陆他的系统,常规办法一般是上传一个htran,然后进行转发,但是对方有杀软,有被杀的可能性,所以我用另外一种办法达 ...
- 慕课网Python基础学习整理
# -*- coding: utf-8 -*- """# Python的注释以 # 开头,后面的文字直到行尾都算注释;多行注释开头3个 " 结尾3个 " ...
- TemplateBinding和Binding的区别
定义 TemplateBinding是为了某个特定场景优化出来的数据绑定版本--需要把ControlTemplate里面的某个Property绑定到应用该ControlTemplate的控件的对应Pr ...
- [中英对照]Linux kernel coding style | Linux内核编码风格
Linux kernel coding style | Linux内核编码风格 This is a short document describing the preferred coding sty ...
- 配置jenkins slave 问题,ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
因为需要需要搭建一套自动化环境的windows电脑作为slave,简单的把原来用来mac上的job配置一模一样的配置了下,运行时遇到如上问题,google半天百思不得其解, 后来尝试把SCM里面的br ...
- C#学习之文件操作
1 DirectoryInfo 类介绍 DirectoryInfo 类在 .net 开发中主要用于创建.移动和枚举目录和子目录的实例方法,此类不能被继承. 从事 .net 软件开发的同事对 Dir ...