首页 > Java > java教程 > 正文

最富有的客户财富

Barbara Streisand
发布: 2024-11-07 06:45:02
原创
768 人浏览过

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中文网其他相关文章!

来源:dev.to
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板