Home  >  Article  >  Java  >  Richest Customer Wealth

Richest Customer Wealth

Barbara Streisand
Barbara StreisandOriginal
2024-11-07 06:45:02702browse

Richest Customer Wealth

Problem

https://leetcode.com/problems/richest-customer-wealth/description/

Solution

class Solution {
public int maximumWealth (int[][] accounts) {
int wealth  = 0;
        for (int[] customer : accounts) {
              int currentCustomerWealth = 0;
    for (int bank : customer) {
              currentCustomerWealth += bank;
    }
           wealth  = Math.max(wealth , currentCustomerWealth);
}
           return wealth ;
}
}

Solution 02

class Solution {
    public int maximumWealth(int[][] accounts) {
        int wealth = 0;
        // Loop through each customer
        for (int i = 0; i < accounts.length; i++) {
            int currentCustomerWealth = 0;
            // Loop through each bank account for the current customer
            for (int j = 0; j < accounts[i].length; j++) {
                currentCustomerWealth += accounts[i][j]; // Add the bank balance to current customer's wealth
            }
            // Update maximum wealth if current is greater
            wealth = Math.max(wealth, currentCustomerWealth);
        }
        return wealth; // Return the maximum wealth found
    }
}

The above is the detailed content of Richest Customer Wealth. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn