Skip to content

Commit 0b7bb03

Browse files
committed
Time: 39 ms (23.3%), Space: 16.4 MB (69.01%) - LeetHub
1 parent 0c47dbf commit 0b7bb03

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def alternateDigitSum(self, n: int) -> int:
3+
s=str(n)
4+
sum=0
5+
for i in range(0,len(s),2):
6+
sum+=ord(s[i])-ord('0')
7+
for i in range(1,len(s),2):
8+
sum-=ord(s[i])-ord('0')
9+
return sum

0 commit comments

Comments
 (0)