Programmers/프로그래머스-숨어있는 숫자의 덧셈(2)-python

cosmos·2022년 12월 2일
0
post-thumbnail

문제

코드

# https://school.programmers.co.kr/learn/courses/30/lessons/120864
# programmers, level0: 숨어있는 숫자의 덧셈 (2), python3
def solution(my_string: str) -> int:
    answer = 0
    num = ''

    for x in my_string:
        if x.isdigit():
            num += x
        else:
            if num:
                answer += int(num)
                num = ''

    if num.isdigit():
        answer += int(num)

    return answer

if __name__ == '__main__':
    print(solution("aAb1B2cC34oOp"))  # 37
    print(solution("1a2b3c4d123Z"))   # 133

결과

출처 & 깃허브

프로그래머스
깃허브

0개의 댓글