添加了python代码(数组篇)

为数组篇文件夹下的代码增加了python语言版本
This commit is contained in:
goodyong
2021-07-10 12:20:02 +08:00
parent 4e661354d4
commit 7dd5ce1f3d
13 changed files with 461 additions and 3 deletions

View File

@@ -44,6 +44,8 @@
我们可以根据当前位 余10来判断这样我们就可以区分属于第几种情况了大家直接看代码吧很容易理解的
Java Code:
```java
class Solution {
public int[] plusOne(int[] digits) {
@@ -65,3 +67,21 @@ class Solution {
}
```
Python Code:
```python
from typing import List
class Solution:
def plusOne(self, digits: List[int])->List[int]:
# 获取长度
leng = len(digits)
for i in range(leng - 1, -1, -1):
digits[i] = (digits[i] + 1) % 10
# 第一种和第二种情况如果此时某一位不为 0 则直接返回即可
if digits[i] != 0:
return digits
# 第三种情况因为数组初始化每一位都为0我们只需将首位设为1即可
arr = [0] * (leng + 1)
arr[0] = 1
return arr
```