mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-04 06:51:34 +00:00
Merge branch 'main' into swift
# Conflicts: # animation-simulation/数组篇/leetcode219数组中重复元素2.md # animation-simulation/数组篇/leetcode59螺旋矩阵2.md # animation-simulation/数组篇/leetcode66加一.md # animation-simulation/数组篇/leetcode75颜色分类.md
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
> 感谢支持,该仓库会一直维护,希望对各位有一丢丢帮助。
|
||||
>
|
||||
> 另外希望手机阅读的同学可以来我的 <u>[**公众号:袁厨的算法小屋**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u> 两个平台同步,想要和题友一起刷题,互相监督的同学,可以在我的小屋点击<u>[**刷题小队**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u>进入。
|
||||
>
|
||||
|
||||
#### [66. 加一](https://leetcode-cn.com/problems/plus-one/)
|
||||
|
||||
@@ -86,6 +85,24 @@ class Solution:
|
||||
return arr
|
||||
```
|
||||
|
||||
C++ Code:
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> plusOne(vector<int>& digits) {
|
||||
for(int i = digits.size() - 1; i >= 0; --i){
|
||||
digits[i] = (digits[i] + 1)%10;
|
||||
if(digits[i]) return digits;
|
||||
}
|
||||
for(int & x: digits) x = 0;
|
||||
digits.emplace_back(1);
|
||||
reverse(digits.begin(), digits.end());
|
||||
return digits;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Swift Code:
|
||||
|
||||
```swift
|
||||
@@ -105,3 +122,4 @@ class Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user