EasyNo. 2553
Separate the Digits in an Array — LeetCode 2553 Python Solution
- Topics
- Array, Simulation
- 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
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
- Time
- O(n × log_10 M)
- Space · auxiliary
- O(n × log_10 M)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0495 | Teemo Attacking | Easy |
| 0985 | Sum of Even Numbers After Queries | Medium |
| 1389 | Create Target Array in the Given Order | Easy |
| 1409 | Queries on a Permutation With Key | Medium |
| 1503 | Last Moment Before All Ants Fall Out of a Plank | Medium |
| 1535 | Find the Winner of an Array Game | Medium |
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 × 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 × 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.