Separate the Digits in an Array — LeetCode 2553 Python Solution
EasyArraySimulation
- Problem
- #2553
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums. To separate the digits of an integer is to get all the digits it has in the same order.
Example
- Input
- nums = [13,25,83,77]
- Output
- [1,3,2,5,8,3,7,7]
- Explanation
- - The separation of 13 is [1,3].
Python solution
Python
class Solution:
def separateDigits(self, nums: List[int]) -> List[int]:
ans = []
for x in nums:
t = []
while x:
t.append(x % 10)
x //= 10
ans.extend(t[::-1])
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n \times \log_{10} M) |
| Space | O(n \times \log_{10} M) auxiliary |
Related problems
LeetCode 495Teemo AttackingEasyLeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1389Create Target Array in the Given OrderEasyLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMediumLeetCode 1535Find the Winner of an Array GameMedium
Frequently asked questions
- How hard is LeetCode 2553. Separate the Digits in an Array?
- LeetCode 2553. Separate the Digits in an Array is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2553. Separate the Digits in an Array?
- The Python solution on this page runs in O(n \times \log_{10} M).
- What is the space complexity of LeetCode 2553. Separate the Digits in an Array?
- The Python solution on this page uses O(n \times \log_{10} M) auxiliary space.
- What topics does LeetCode 2553. Separate the Digits in an Array cover?
- LeetCode 2553. Separate the Digits in an Array is tagged Array and Simulation on LeetCode.