LeetCode/Array

[Easy]1672. Richest Customer Wealth

Developer07 2022. 8. 27. 10:57

Leetcode 1672번 문제는 integer array를 담고 있는 array가 주어진다. 각 array를 더했을 때 가장 값이 큰 값을 return 하면 된다. 간단한 nested for-loop의로 풀 수 있다.

class Solution {
    public int maximumWealth(int[][] accounts) {
        int res = 0;
        for(int i =0;i<accounts.length;i++){
            int temp = 0;
            for(int j = 0;j<accounts[i].length;j++){
                temp+=accounts[i][j];
            }
            res = Math.max(res,temp);
        }
        return res;
    }
}