Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- leetcode 풀기
- 알고리즘풀기
- python 릿코드
- 릿코드 풀기
- python priority queue
- python sorted
- 알고리즘풀이
- LeetCode
- 잇츠디모
- 파이썬 릿코드
- leetcode풀기
- python Leetcode
- 파이썬 프로그래머스
- 릿코드
- 릿코드 파이썬
- 릿코드풀기
- 상가수익률계산기
- 파이썬알고리즘풀기
- python xor
- 파이썬릿코드
- python zip_longest
- 파이썬알고리즘
- 코틀린기초
- 파이썬릿코드풀기
- 파이썬 알고리즘 풀기
- 파이썬 알고리즘
- binary search
- python 알고리즘
- leetcode풀이
- 릿코드풀이
Archives
- Today
- Total
소프트웨어에 대한 모든 것
LeetCode 풀기 - 1281. Subtract the Product and Sum of Digits of an Integer 본문
알고리즘/LeetCode
LeetCode 풀기 - 1281. Subtract the Product and Sum of Digits of an Integer
앤테바 2021. 11. 6. 23:03반응형
1281. Subtract the Product and Sum of Digits of an Integer
https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
Subtract the Product and Sum of Digits of an Integer - LeetCode
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
문제)
솔루션1)
숫자를 숫자 리스트 형태로 변환한다.
숫자 리스트에 대해서 reduce()를 적용해서 product, max 값을 취해서 차를 구한다.
class Solution:
def subtractProductAndSum(self, n: int) -> int:
arr = list(map(int, str(n)))
return reduce(lambda x, y: x * y, arr) - sum(arr)
솔루션2)
math.prod 함수를 사용해서 곱셉 연산을 한다.
class Solution:
def subtractProductAndSum(self, n: int) -> int:
arr = list(map(int, str(n)))
return math.prod(arr) - sum(arr)
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
LeetCode 풀기 - 1342. Number of Steps to Reduce a Number to Zero (0) | 2021.11.07 |
---|---|
LeetCode 풀기 - 1877. Minimize Maximum Pair Sum in Array (0) | 2021.11.06 |
LeetCode 풀기 - 1720. Decode XORed Array (0) | 2021.11.06 |
LeetCode 풀기 - 1221. Split a String in Balanced Strings (0) | 2021.11.06 |
LeetCode 풀기 - 1302. Deepest Leaves Sum (0) | 2021.11.06 |
Comments