首页  >  文章  >  Java  >  最富有的客户财富

最富有的客户财富

Barbara Streisand
Barbara Streisand原创
2024-11-07 06:45:02702浏览

Richest Customer Wealth

问题

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

解决方案

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 ;
}
}

解决方案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
    }
}

以上是最富有的客户财富的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn