MCPcopy Index your code
hub / github.com/doocs/leetcode / addStrings

Method addStrings

solution/0400-0499/0415.Add Strings/Solution.py:2–12  ·  view source on GitHub ↗
(self, num1: str, num2: str)

Source from the content-addressed store, hash-verified

1class Solution:
2 def addStrings(self, num1: str, num2: str) -> str:
3 i, j = len(num1) - 1, len(num2) - 1
4 ans = []
5 c = 0
6 while i >= 0 or j >= 0 or c:
7 a = 0 if i < 0 else int(num1[i])
8 b = 0 if j < 0 else int(num2[j])
9 c, v = divmod(a + b + c, 10)
10 ans.append(str(v))
11 i, j = i - 1, j - 1
12 return "".join(ans[::-1])
13
14 def subStrings(self, num1: str, num2: str) -> str:
15 m, n = len(num1), len(num2)

Callers

nothing calls this directly

Calls 2

appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected