반응형
Create a function that takes 2 integers in form of a string as an input, and outputs the sum (also as a string):
Example: (Input1, Input2 -->Output)
"4", "5" --> "9"
"34", "5" --> "39"
"", "" --> "0"
"2", "" --> "2"
"-5", "3" --> "-2"
Notes:
-
If either input is an empty string, consider it as zero.
-
Inputs and the expected output will never exceed the signed 32-bit integer limit (2^31 - 1)
Solution:
def sum_str(a, b):
return f"{sum(map(_int, [a, b]))}"
def _int(s: str):
return int(s or 0)
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1026. Beginner Series #4 Cockroach (0) | 2022.10.26 |
---|---|
1025. Exclusive "or" (xor) Logical Operator (0) | 2022.10.26 |
1023. No Loops 2 - You only need one (0) | 2022.10.23 |
1022. Area of a Square (0) | 2022.10.22 |
1021. USD => CNY (0) | 2022.10.21 |