【LeetCode】LC1672. 最富有客户的资产总量
生活随笔
收集整理的這篇文章主要介紹了
【LeetCode】LC1672. 最富有客户的资产总量
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
算法思想
Java實例代碼&測試代碼
public class LC1672 {public int maximumWealth(int[][] accounts) {int ans = 0;for (int i = 0; i < accounts.length; i++) {int tmp = 0;for (int j = 0; j < accounts[i].length; j++) {tmp += accounts[i][j];}ans = tmp > ans ? tmp : ans;}return ans;}public static void main(String[] args) {int[][] accounts = {{1,2,3},{3,2,1},{3,5}};LC1672 lc1672 = new LC1672();int ans = lc1672.maximumWealth(accounts);System.out.println(ans);} }算法分析
時間復雜度:O(mn),遍歷而數組數中的每一個數
空間復雜度:O(2)~O(1),只需要一個參數記錄ans的值和tmp即可
總結
以上是生活随笔為你收集整理的【LeetCode】LC1672. 最富有客户的资产总量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【LeetCode】LC1408:一维数
- 下一篇: 【设计模式】单一职责原则