반응형
Problem
이번 문제는 리스트 안에 리스트 의 합 중에서 최대 값을 return 하는 쉬운 문제이다
나의 풀이
class Solution:
def maximumWealth(self, accounts: List[List[int]]) -> int:
res = [sum(account) for account in accounts]
return max(res)
기본적인 sum 과 max를 이용하여 문제를 풀었다
당연히 다른사람의 머리속을 들어가 봐야한다.
class Solution:
def maximumWealth(self, accounts: List[List[int]]) -> int:
return max(map(sum, accounts))
오..... 굉장하다
map을 사용하여 정말 간결하게 코드를 구현했다
map 예시
>>> a = [1.2, 2.5, 3.7, 4.6]
>>> a = list(map(int, a))
>>> a
[1, 2, 3, 4]
오늘 또 간단간단 파이썬 사고방식을 하나배워간다.
반응형
'Python > algorithm' 카테고리의 다른 글
[Leetcode] 2114. Maximum Number of Words Found in Sentences (0) | 2022.12.29 |
---|---|
[Leetcode] 771. Jewels and Stones (0) | 2022.12.27 |
[Leetcode] 1512. Number of Good Pairs (0) | 2022.12.25 |
[Leetcode] 1470. Shuffle the Array (1) | 2022.12.21 |
[Leetcode] 2011. Final Value of Variable After Performing Operations (1) | 2022.12.20 |