最富有客户的资产总量
| Category | Difficulty | Likes | Dislikes |
|---|---|---|---|
| algorithms | Easy (86.41%) | 150 | - |
<details style="color: rgb(225, 228, 232); font-family: -apple-system, "system-ui", "Segoe WPC", "Segoe UI", system-ui, Ubuntu, "Droid Sans", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><summary><strong>Tags</strong></summary><p style="margin-top: 0px; margin-bottom: 0.7em;"><a href="https://leetcode.com/tag/Unknown" title="https://leetcode.com/tag/Unknown" style="color: var(--vscode-textLink-foreground); text-decoration: none;"><code style="color: var(--vscode-textLink-foreground); font-family: var(--vscode-editor-font-family, "SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace); font-size: 1em; line-height: 1.357em; white-space: pre-wrap;"></code></a></p></details>
<details style="color: rgb(225, 228, 232); font-family: -apple-system, "system-ui", "Segoe WPC", "Segoe UI", system-ui, Ubuntu, "Droid Sans", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><summary><strong>Companies</strong></summary><p style="margin-top: 0px; margin-bottom: 0.7em;"><code style="color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, "SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace); font-size: 1em; line-height: 1.357em; white-space: pre-wrap;"></code></p></details>
给你一个 m x n 的整数网格 accounts ,其中 accounts[i][j] 是第 i 位客户在第 j 家银行托管的资产数量。返回最富有客户所拥有的 资产总量 。
客户的 资产总量 就是他们在各家银行托管的资产数量之和。最富有客户就是 资产总量 最大的客户。
示例 1:
输入:accounts = [[1,2,3],[3,2,1]]
输出:6
解释:
第 1 位客户的资产总量 = 1 + 2 + 3 = 6
第 2 位客户的资产总量 = 3 + 2 + 1 = 6
两位客户都是最富有的,资产总量都是 6 ,所以返回 6 。示例 2:
输入:accounts = [[1,5],[7,3],[3,5]]
输出:10
解释:
第 1 位客户的资产总量 = 6
第 2 位客户的资产总量 = 10
第 3 位客户的资产总量 = 8
第 2 位客户是最富有的,资产总量是 10示例 3:
输入:accounts = [[2,8,7],[7,1,3],[1,9,5]]
输出:17提示:
m == accounts.lengthn == accounts[i].length1 <= m, n <= 501 <= accounts[i][j] <= 100
Code Now
/*
* @Author: 仲灏<izhaong@outlook.com>🌶🌶🌶
* @Date: 2022-11-07 10:35:48
* @LastEditTime: 2022-11-07 11:27:24
* @LastEditors: 仲灏<izhaong@outlook.com>🌶🌶🌶
* @Description:
* @FilePath: /leetcode/1672.最富有客户的资产总量.ts
*/
/*
* @lc app=leetcode.cn id=1672 lang=typescript
*
* [1672] 最富有客户的资产总量
*
* https://leetcode.cn/problems/richest-customer-wealth/description/
*
* algorithms
* Easy (86.41%)
* Likes: 150
* Dislikes: 0
* Total Accepted: 111.4K
* Total Submissions: 128.9K
* Testcase Example: '[[1,2,3],[3,2,1]]'
*
* 给你一个 m x n 的整数网格 accounts ,其中 accounts[i][j] 是第 i^ 位客户在第 j
* 家银行托管的资产数量。返回最富有客户所拥有的 资产总量 。
*
* 客户的 资产总量 就是他们在各家银行托管的资产数量之和。最富有客户就是 资产总量 最大的客户。
*
*
*
* 示例 1:
*
* 输入:accounts = [[1,2,3],[3,2,1]]
* 输出:6
* 解释:
* 第 1 位客户的资产总量 = 1 + 2 + 3 = 6
* 第 2 位客户的资产总量 = 3 + 2 + 1 = 6
* 两位客户都是最富有的,资产总量都是 6 ,所以返回 6 。
*
*
* 示例 2:
*
* 输入:accounts = [[1,5],[7,3],[3,5]]
* 输出:10
* 解释:
* 第 1 位客户的资产总量 = 6
* 第 2 位客户的资产总量 = 10
* 第 3 位客户的资产总量 = 8
* 第 2 位客户是最富有的,资产总量是 10
*
* 示例 3:
*
* 输入:accounts = [[2,8,7],[7,1,3],[1,9,5]]
* 输出:17
*
*
*
*
* 提示:
*
*
* m == accounts.length
* n == accounts[i].length
* 1 <= m, n <= 50
* 1 <= accounts[i][j] <= 100
*
*
*/
// @lc code=start
// function maximumWealth(accounts: number[][]): number {
// let maxCount = 0
// for (let i = 0; i < accounts.length; i++) {
// const u = accounts[i];
// let um = 0
// for (let j = 0; j < u.length; j++) {
// const m = u[j];
// um += m
// }
// if(um > maxCount) maxCount = um
// }
// return maxCount
// };
function maximumWealth(accounts: number[][]): number {
let maxCount = 0;
for (let i = 0; i < accounts.length; i++) {
const u = accounts[i];
let um = 0;
maxCount = Math.max(
maxCount,
u.reduce((a, b) => a + b)
);
}
return maxCount;
}
// @lc code=end