LeetCode—1672

Approach

# 將每行的值加起來,最後比較是不是最大值
Sum the values in each row, then compare to see which one is the largest.

Time Complexity

# n = accounts; m = number in the accounts
O(n * m)

Space Complexity

# n = accounts; m = number in the accounts
O(n * m)

Code

class Solution {
public:
    int maximumWealth(vector<vector<int>>& accounts) {
        int l = accounts.size(), ans = -1;

        for (int i = 0 ; i < l ; i++) {
            int l2 = accounts[i].size(), sum = 0;

            for (int j = 0 ; j < l2 ; j++) {
                sum += accounts[i][j];
            }

            ans = max(ans, sum);
        }

        return ans;
    }
};