Notice
Recent Posts
Recent Comments
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

[Intro] All Longest Strings 본문

프로그래밍/CodeSignal

[Intro] All Longest Strings

CHIqueen 2020. 3. 11. 12:59
def allLongestStrings(inputArray):
    maxd = 0
    for i in inputArray:
        maxd = max(maxd,len(i))
    return [i for i in inputArray if len(i) == maxd]

나머지 풀이들을 봤는데 max함수에 key를 len으로만 줘서 반복문 돌릴필요가 없었던것이 신기했다.

def allLongestStrings(inputArray):
    return [i for i in inputArray if len(i) == len(max(inputArray, key=len))]

 

'프로그래밍 > CodeSignal' 카테고리의 다른 글

[Intro] isLucky  (0) 2020.03.11
[Intro] commonCharacterCount  (0) 2020.03.11
[Intro] matrixElementsSum  (0) 2020.03.11
[Intro] shapeArea  (0) 2020.03.03
[Intro] Make Array Consecutive 2  (0) 2020.03.03
Comments