Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- ubuntu
- hackerrank
- 데이콘
- 코로나19
- 금융문자분석경진대회
- 자연어처리
- AI 경진대회
- 맥북
- 캐치카페
- gs25
- Git
- Docker
- github
- programmers
- leetcode
- 편스토랑 우승상품
- 프로그래머스 파이썬
- 프로그래머스
- Baekjoon
- Kaggle
- 편스토랑
- PYTHON
- 우분투
- 백준
- Real or Not? NLP with Disaster Tweets
- SW Expert Academy
- ChatGPT
- dacon
- 파이썬
- 더현대서울 맛집
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 66. Plus One (Python) 본문
728x90
반응형
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1:
Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Example 2:
Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.
Solution
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
num_string_list = list(map(str, digits))
num_string = ''.join(num_string_list)
my_number = int(num_string)
answer_number = my_number + 1
answer_number_string = str(answer_number)
answer_number_list = list(answer_number_string)
answer = list(map(int, answer_number_list))
return answer
코드를 조금 줄인 Solution
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
num_string_list = list(map(str, digits))
num_string = ''.join(num_string_list)
my_number = int(num_string) + 1
answer_number_string = list(str(my_number))
answer = list(map(int, answer_number_string))
return answer
SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[SW_Expert_Academy] 5948번 새샘이의 7-3-5 게임 (Python) (0) | 2020.05.22 |
---|---|
[SW_Expert_Academy] 5162번 두가지 빵의 딜레마 (Python) (0) | 2020.05.21 |
[leetCode] 69. Sqrt(x) (Python) (0) | 2020.05.19 |
[leetCode] 8. String to Integer (atoi) (Python) (0) | 2020.05.18 |
[BaeKJoon] 11727번: 2xn타일링 2 (Python) (0) | 2020.05.17 |
Comments