Algorithm/LeetCode

[LeetCode] Richest Customer Wealth

You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i​​​​​​​​​​​th​​​​ customer has in the j​​​​​​​​​​​th​​​​ bank. Return the wealth that the richest customer has.

A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.

 

class Solution {
    public int maximumWealth(int[][] accounts) {
        int biggestValue = 0;
        
        for(int idx = 0; idx < accounts.length; idx ++){
        	int temp = 0;
            for(int i = 0; i < accounts[idx].length; i++) {
            	temp = temp + accounts[idx][i];
            }
            if(biggestValue <= temp) biggestValue = temp;
        }
        
        return biggestValue;
    }
}

Runtime: 0 ms, faster than 100.00% of Java online submissions for Richest Customer Wealth.
Memory Usage: 38.4 MB, less than 71.43% of Java online submissions for Richest Customer Wealth.

 

class Solution {
    public int maximumWealth(int[][] accounts) {
        int max = 0;
        for (int[] account : accounts) {
            int temp = 0;
            for (int i : account) {
                temp += i;
            }
            if (temp > max) {
                max = temp;
            }
        }
        System.gc();
        return max;
    }
}

Runtime: 0 ms, faster than 100.00% of Java online submissions for Richest Customer Wealth.
Memory Usage: 37.7 MB, less than 99.94% of Java online submissions for Richest Customer Wealth.

메모리는 역시 System.gc()를 통해 줄이는 모습이다.

그런데 실무에서 저거 쓰면 쓰레드 멈추기 때문에 실제 사용할 일이 있을까 싶다.