Leetcode 1672. Richest Customer Wealth

Problem

You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i​​​​​​​​​​​th​​​​ customer has in the j​​​​​​​​​​​th​​​​ bank. Return the wealth that the richest customer has.

A customer’s wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.

Algorithm

Add up the numbers in each row, and then take the maximum.

Code

class Solution:
    def maximumWealth(self, accounts: List[List[int]]) -> int:
        slen = len(accounts)
        ans = [0] * slen
        for i in range(slen):
            ans[i] = sum(accounts[i])
        
        return max(ans)

你可能感兴趣的:(Leetcode,解题报告,leetcode,算法,职场和发展)