{"id":7733,"date":"2020-11-29T01:47:42","date_gmt":"2020-11-29T09:47:42","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=7733"},"modified":"2020-11-29T01:51:38","modified_gmt":"2020-11-29T09:51:38","slug":"leetcode-1672-richest-customer-wealth","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/algorithms\/array\/leetcode-1672-richest-customer-wealth\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 1672. Richest Customer Wealth"},"content":{"rendered":"\n<p>You are given an&nbsp;<code>m x n<\/code>&nbsp;integer grid&nbsp;<code>accounts<\/code>&nbsp;where&nbsp;<code>accounts[i][j]<\/code>&nbsp;is the amount of money the&nbsp;<code>i\u200b\u200b\u200b\u200b\u200b<sup>\u200b\u200b\u200b\u200b\u200b\u200bth<\/sup>\u200b\u200b\u200b\u200b<\/code>&nbsp;customer has in the&nbsp;<code>j\u200b\u200b\u200b\u200b\u200b<sup>\u200b\u200b\u200b\u200b\u200b\u200bth<\/sup><\/code>\u200b\u200b\u200b\u200b bank. Return<em>&nbsp;the&nbsp;<strong>wealth<\/strong>&nbsp;that the richest customer has.<\/em><\/p>\n\n\n\n<p>A customer&#8217;s&nbsp;<strong>wealth<\/strong>&nbsp;is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum&nbsp;<strong>wealth<\/strong>.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> accounts = [[1,2,3],[3,2,1]]\n<strong>Output:<\/strong> 6\n<strong>Explanation<\/strong><strong>:<\/strong>\n<code>1st customer has wealth = 1 + 2 + 3 = 6\n<\/code><code>2nd customer has wealth = 3 + 2 + 1 = 6\n<\/code>Both customers are considered the richest with a wealth of 6 each, so return 6.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> accounts = [[1,5],[7,3],[3,5]]\n<strong>Output:<\/strong> 10\n<strong>Explanation<\/strong>: \n1st customer has wealth = 6\n2nd customer has wealth = 10 \n3rd customer has wealth = 8\nThe 2nd customer is the richest with a wealth of 10.<\/pre>\n\n\n\n<p><strong>Example 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> accounts = [[2,8,7],[7,1,3],[1,9,5]]\n<strong>Output:<\/strong> 17\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>m ==&nbsp;accounts.length<\/code><\/li><li><code>n ==&nbsp;accounts[i].length<\/code><\/li><li><code>1 &lt;= m, n &lt;= 50<\/code><\/li><li><code>1 &lt;= accounts[i][j] &lt;= 100<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Sum each row up<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(mn)<br>Space complexity: O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\n\/\/ Author: Huahua\nclass Solution {\npublic:\n  int maximumWealth(vector<vector<int>>& accounts) {\n    int ans = 0;\n    for (const vector<int>& row : accounts)\n      ans = max(ans, accumulate(begin(row), end(row), 0));\n    return ans;\n  }\n};\n<\/pre>\n\n<\/div><h2 class=\"tabtitle\">Python3<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"python\">\n# Author: Huahua\nclass Solution:\n  def maximumWealth(self, accounts: List[List[int]]) -> int:\n    return max(sum(account) for account in accounts)\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You are given an&nbsp;m x n&nbsp;integer grid&nbsp;accounts&nbsp;where&nbsp;accounts[i][j]&nbsp;is the amount of money the&nbsp;i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b&nbsp;customer has in the&nbsp;j\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b bank. Return&nbsp;the&nbsp;wealth&nbsp;that the richest customer has. A customer&#8217;s&nbsp;wealth&nbsp;is the amount&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[20,222,216,62],"class_list":["post-7733","post","type-post","status-publish","format-standard","hentry","category-array","tag-array","tag-easy","tag-matrix","tag-sum","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=7733"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7733\/revisions"}],"predecessor-version":[{"id":7735,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7733\/revisions\/7735"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=7733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=7733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=7733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}