본문 바로가기

Algorithm/Implementation

(Python3) - LeetCode (easy) 989. Add to Array-Form of Integer

반응형

https://leetcode.com/problems/add-to-array-form-of-integer/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

큰 수 다루는 문제였습니다.

📕 풀이방법

📔 풀이과정

큰 수 사칙연산을 지원하는 python3을 사용해 풀었습니다.1. int로의 문자열 변환에 사용할 수 있는 문자열의 최대 길이가 10000자로 제한되어 있어 최대 15000자리까지 지원하도록 sys를 수정해줍니다.2. num를 수로 변환후 k와 더한 값의 결과를 map함수를 사용해 int로 변환 후 list로 반환해줍니다.


📕 Code

📔 Python3

import sys

sys.set_int_max_str_digits(15000)

class Solution:
    def addToArrayForm(self, num: List[int], k: int) -> List[int]:
        num = int(''.join(map(str,num)))
        return list(map(int, str(k+num)))

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.