You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth 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()를 통해 줄이는 모습이다.
그런데 실무에서 저거 쓰면 쓰레드 멈추기 때문에 실제 사용할 일이 있을까 싶다.
'Algorithm > LeetCode' 카테고리의 다른 글
[LeetCode] Number of Good Pairs (0) | 2021.06.16 |
---|---|
[LeetCode] Kids With the Greatest Number of Candies (0) | 2021.06.14 |
[LeetCode] Shuffle the Array (0) | 2021.06.11 |
[LeetCode] Running Sum of 1d Array (0) | 2021.06.08 |
[LeetCode] Check if Word Equals Summation of Two Words (0) | 2021.06.07 |