Skip to content

Commit 5c48ee3

Browse files
committed
新增 Python 和 C++ 实现的加法数字函数,包含基本逻辑
1 parent c3440dd commit 5c48ee3

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def isPowerOfTwo(self, n: int) -> bool:
3+
return n > 0 and (n&(n-1) ) == 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
public:
3+
int addDigits(int num) {
4+
return num > 0 ? (num-1)%9 + 1 : 0;
5+
}
6+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def addDigits(self, num: int) -> int:
3+
return (num-1) % 9 + 1 if num else 0

0 commit comments

Comments
 (0)