首頁  >  文章  >  Java  >  最富有的客戶財富

最富有的客戶財富

Barbara Streisand
Barbara Streisand原創
2024-11-07 06:45:02778瀏覽

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