修改部分错字 & 优化变量名命名

This commit is contained in:
erdengk
2022-02-16 16:23:39 +08:00
parent 46ceb72cd0
commit f39d5a110c
2 changed files with 12 additions and 12 deletions

View File

@ -89,9 +89,9 @@ TreeNode* traversal (vector<int>& inorder, vector<int>& postorder) {
**难点大家应该发现了,就是如何切割,以及边界值找不好很容易乱套。** **难点大家应该发现了,就是如何切割,以及边界值找不好很容易乱套。**
此时应该注意确定切割的标准,是左闭右开,还有左开闭,还是左闭闭,这个就是不变量,要在递归中保持这个不变量。 此时应该注意确定切割的标准,是左闭右开,还有左开闭,还是左闭闭,这个就是不变量,要在递归中保持这个不变量。
**在切割的过程中会产生四个区间,把握不好不变量的话,一会左闭右开,一会左闭闭,必然乱套!** **在切割的过程中会产生四个区间,把握不好不变量的话,一会左闭右开,一会左闭闭,必然乱套!**
我在[数组:每次遇到二分法,都是一看就会,一写就废](https://programmercarl.com/0035.搜索插入位置.html)和[数组:这个循环可以转懵很多人!](https://programmercarl.com/0059.螺旋矩阵II.html)中都强调过循环不变量的重要性,在二分查找以及螺旋矩阵的求解中,坚持循环不变量非常重要,本题也是。 我在[数组:每次遇到二分法,都是一看就会,一写就废](https://programmercarl.com/0035.搜索插入位置.html)和[数组:这个循环可以转懵很多人!](https://programmercarl.com/0059.螺旋矩阵II.html)中都强调过循环不变量的重要性,在二分查找以及螺旋矩阵的求解中,坚持循环不变量非常重要,本题也是。

View File

@ -128,24 +128,24 @@ public:
```java ```java
class Solution { class Solution {
public boolean lemonadeChange(int[] bills) { public boolean lemonadeChange(int[] bills) {
int cash_5 = 0; int five = 0;
int cash_10 = 0; int ten = 0;
for (int i = 0; i < bills.length; i++) { for (int i = 0; i < bills.length; i++) {
if (bills[i] == 5) { if (bills[i] == 5) {
cash_5++; five++;
} else if (bills[i] == 10) { } else if (bills[i] == 10) {
cash_5--; five--;
cash_10++; ten++;
} else if (bills[i] == 20) { } else if (bills[i] == 20) {
if (cash_10 > 0) { if (ten > 0) {
cash_10--; ten--;
cash_5--; five--;
} else { } else {
cash_5 -= 3; five -= 3;
} }
} }
if (cash_5 < 0 || cash_10 < 0) return false; if (five < 0 || ten < 0) return false;
} }
return true; return true;