simele-total assets of the richest client

Give you an mxn integer grid of accounts, where accounts[i][j] is the number of assets held by the i-th customer in the j-th bank. Returns the total amount of assets owned by the richest customer.

The total assets of a customer is the sum of the assets they have in custody in various banks. The richest client is the client with the largest total assets.

Input: accounts = [[1,2,3],[3,2,1]]
Output: 6
Explanation:
Total assets of the first customer = 1 + 2 + 3 = 6
Total assets of the second customer = 3 + 2 + 1 = 6
Both customers are the richest, and the total assets are both 6, so 6 is returned.

Source: LeetCode
Link: https://leetcode-cn.com/problems/richest-customer-wealth
Copyright is owned by LeetCode . For commercial reprints, please contact the official authorization. For non-commercial reprints, please indicate the source.

public static int theWealthiestCustomer(int arr[][]){
    
    
      
        int weathiestVal=0;
        int count=0;

        for (int i = 0; i < arr[0].length; i++) {
    
    
            weathiestVal +=arr[0][i];
        }

        for (int i = 0; i < arr.length; i++) {
    
    
            count=0;
            for (int j = 0; j < arr[i].length; j++) {
    
    
                count += arr[i][j];
            }
            if(count>weathiestVal){
    
    
                weathiestVal=count;
            
            }
        }
        return weathiestVal;
    }

Guess you like

Origin blog.csdn.net/qq_41729287/article/details/112346372