본문 바로가기
IT/알고리즘

78] 1672. Richest Customer Wealth Kotlin

by 깻잎쌈 2023. 4. 19.
반응형

https://leetcode.com/problems/richest-customer-wealth/description/

 

Richest Customer Wealth - LeetCode

Can you solve this real interview question? 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 custom

leetcode.com

 

2차원 int 배열이 주어질때 

각 행의 합 중 최대값을 리턴하는 문제.

class Solution {
    fun maximumWealth(accounts: Array<IntArray>): Int {

        var ans = 0
        for(i in 0 until accounts.size) {
            var cnt = 0
            for(j in 0 until accounts[i].size) {
                cnt += accounts[i][j]
            }

            if(ans < cnt)
              ans = cnt
        }

        return ans
    }
}

 

 

반응형

댓글