반응형
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)))
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++, Rust) - LeetCode (easy) 1009. Complement of Base 10 Integer (0) | 2023.09.26 |
---|---|
(C++) - LeetCode (easy) 999. Available Captures for Rook (0) | 2023.09.22 |
(C++, Rust) - LeetCode (easy) 941. Valid Mountain Array (0) | 2023.09.11 |
(C++) - LeetCode (easy) 941. Valid Mountain Array (0) | 2023.09.08 |
(C++, Rust) - LeetCode (easy) 925. Long Pressed Name (0) | 2023.09.04 |