Skip to content

Commit 26ccde8

Browse files
committed
📝 docs : add 258. Add Digits.md
1 parent dc8c07f commit 26ccde8

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## 258. 各位相加
2+
> https://leetcode-cn.com/problems/add-digits/
3+
4+
5+
### Java
6+
```java
7+
/*
8+
* @Author: Goog Tech
9+
* @Date: 2020-08-16 14:24:10
10+
* @LastEditTime: 2020-08-16 14:25:49
11+
* @Description: https://leetcode-cn.com/problems/add-digits/
12+
* @FilePath: \leetcode-googtech\#258. Add Digits\Solution.java
13+
* @WebSite: https://algorithm.show/
14+
*/
15+
16+
class Solution {
17+
public int addDigits(int num) {
18+
if(num < 10) return num;
19+
return num % 9 == 0 ? 9 : num % 9;
20+
}
21+
}
22+
```
23+
24+
### Python
25+
```python
26+
'''
27+
Author: Goog Tech
28+
Date: 2020-08-16 14:25:08
29+
LastEditTime: 2020-08-16 14:25:22
30+
Description: https://leetcode-cn.com/problems/add-digits/
31+
FilePath: \leetcode-googtech\#258. Add Digits\Solution.py
32+
WebSite: https://algorithm.show/
33+
'''
34+
35+
class Solution(object):
36+
def addDigits(self, num):
37+
"""
38+
:type num: int
39+
:rtype: int
40+
"""
41+
if num < 10: return num
42+
return 9 if num % 9 == 0 else num % 9
43+
```

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
* [232.用栈实现队列](LeetCod刷题之旅及题目解析/232.用栈实现队列/232.用栈实现队列.md)
5656
* [234.回文链表](LeetCod刷题之旅及题目解析/234.回文链表/234.回文链表.md)
5757
* [237.删除链表中的节点](LeetCod刷题之旅及题目解析/237.删除链表中的节点/237.删除链表中的节点.md)
58+
* [258.各位相加](LeetCod刷题之旅及题目解析/258.各位相加/258.各位相加.md)
5859
* [283.移动零](LeetCod刷题之旅及题目解析/283.移动零/283.移动零.md)
5960
* [344.反转字符串](LeetCod刷题之旅及题目解析/344.反转字符串/344.反转字符串.md)
6061
* [345.反转字符串中的元音字母](LeetCod刷题之旅及题目解析/345.反转字符串中的元音字母/345.反转字符串中的元音字母.md)

0 commit comments

Comments
 (0)