Skip to content

Commit 7f20f00

Browse files
committed
feat: update solutions to lc problems: No.1672,0072
1 parent 9ff2ad3 commit 7f20f00

File tree

8 files changed

+15
-33
lines changed

8 files changed

+15
-33
lines changed

solution/0000-0099/0072.Edit Distance/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ i, j 分别从 1 开始遍历,判断 `word1[i - 1]` 与 `word2[j - 1]` 是否
6666
-`word1[i - 1] == word2[j - 1]`,则 `dp[i][j] = dp[i - 1][j - 1]`
6767
-`word1[i - 1] != word2[j - 1]`,则 `dp[i][j] = min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1`。其中 `dp[i - 1][j] + 1` 对应插入操作,`dp[i][j - 1] + 1` 对应删除操作,`dp[i - 1][j - 1] + 1` 对应替换操作。取三者的最小值即可。
6868

69+
递推公式如下:
70+
71+
![](https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0072.Edit%20Distance/images/gif.gif)
72+
6973
最后返回 `dp[m][n]` 即可。
7074

7175
<!-- tabs:start -->

solution/0000-0099/0072.Edit Distance/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ exection -&gt; execution (insert &#39;u&#39;)
5151

5252
Dynamic programming.
5353

54+
![](https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0072.Edit%20Distance/images/gif.gif)
55+
5456
<!-- tabs:start -->
5557

5658
### **Python3**
Loading
Loading

solution/1600-1699/1672.Richest Customer Wealth/README.md

+3-11
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@
6363
```python
6464
class Solution:
6565
def maximumWealth(self, accounts: List[List[int]]) -> int:
66-
res = 0
67-
for account in accounts:
68-
res = max(res, sum(account))
69-
return res
66+
return max(sum(account) for account in accounts)
7067
```
7168

7269
### **Java**
@@ -96,13 +93,8 @@ class Solution {
9693
public:
9794
int maximumWealth(vector<vector<int>>& accounts) {
9895
int res = 0;
99-
for (auto& account : accounts) {
100-
int t = 0;
101-
for (auto& money : account) {
102-
t += money;
103-
}
104-
res = max(res, t);
105-
}
96+
for (auto& account : accounts)
97+
res = max(res, accumulate(account.begin(), account.end(), 0));
10698
return res;
10799
}
108100
};

solution/1600-1699/1672.Richest Customer Wealth/README_EN.md

+3-11
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ The 2nd customer is the richest with a wealth of 10.</pre>
5858
```python
5959
class Solution:
6060
def maximumWealth(self, accounts: List[List[int]]) -> int:
61-
res = 0
62-
for account in accounts:
63-
res = max(res, sum(account))
64-
return res
61+
return max(sum(account) for account in accounts)
6562
```
6663

6764
### **Java**
@@ -89,13 +86,8 @@ class Solution {
8986
public:
9087
int maximumWealth(vector<vector<int>>& accounts) {
9188
int res = 0;
92-
for (auto& account : accounts) {
93-
int t = 0;
94-
for (auto& money : account) {
95-
t += money;
96-
}
97-
res = max(res, t);
98-
}
89+
for (auto& account : accounts)
90+
res = max(res, accumulate(account.begin(), account.end(), 0));
9991
return res;
10092
}
10193
};

solution/1600-1699/1672.Richest Customer Wealth/Solution.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ class Solution {
22
public:
33
int maximumWealth(vector<vector<int>>& accounts) {
44
int res = 0;
5-
for (auto& account : accounts) {
6-
int t = 0;
7-
for (auto& money : account) {
8-
t += money;
9-
}
10-
res = max(res, t);
11-
}
5+
for (auto& account : accounts)
6+
res = max(res, accumulate(account.begin(), account.end(), 0));
127
return res;
138
}
149
};
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
class Solution:
22
def maximumWealth(self, accounts: List[List[int]]) -> int:
3-
res = 0
4-
for account in accounts:
5-
res = max(res, sum(account))
6-
return res
3+
return max(sum(account) for account in accounts)

0 commit comments

Comments
 (0)