Computer Science/알고리즘 문제풀이
[codesignal][python] 7. AllLongestStrings
MLra
2020. 12. 27. 12:44
Coding Tests and Assessments for Technical Hiring | CodeSignal
Learn how you can go beyond resumes in technical hiring with a state-of-the-art assessment platform and advanced coding tests
codesignal.com
level : easy
Question:
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 be
allLongestStrings(inputArray) = ["aba", "vcd", "aba"].
My answer:
def allLongestStrings(inputArray):
maxlen=max(list(map(lambda a:len(a),inputArray)))
solution=[]
for name in inputArray:
if maxlen==len(name):
solution.append(name)
return solution
- maxlen에 이 리스트에 문자열 중 가장 긴 길이를 갖는 문자열의 길이가 얼만지를 담는다
- for문을 돌면서 maxlen에 해당하는 요소를 리스트에 append한 후 반환