Python/algorithm

[Leetcode] 1672. Richest Customer WealthEasy2.9K305

baecode 2022. 12. 26. 18:58
반응형

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]

 

오늘 또 간단간단 파이썬 사고방식을 하나배워간다.

반응형