Skip to main content
Back to problems
Leetcode
Easy
Arrays
Math
Simulation
Separate the Digits in an Array

Split every integer in the array into its decimal digits and return all digits in the original order.

Acceptance 100%
Problem Statement

Problem

You are given an integer array nums. For every number in nums, separate its digits and append those digits to a result array in the same left-to-right order they appear in the number.

For example, if a number is 123, it contributes 1, 2, then 3 to the result.

Return the final array of digits after processing every number in order.

Notes

  • The relative order of the input numbers must be preserved.
  • The digits of each number must also keep their original order.
  • The input values are non-negative integers.

Input Format

  • nums: an integer array

Each element is a non-negative integer whose decimal digits should be separated.

Output Format

Return an integer array containing all digits from all numbers in nums, in input order.

Constraints

  • 1 <= nums.length
  • 0 <= nums[i]
  • Each number is represented in base 10

These are prep-oriented constraints and may vary slightly by platform version.

Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [13,25,83,77]

Output

[1,3,2,5,8,3,7,7]

Explanation

Split each number into digits and concatenate the digits in the same order as the numbers appear.

Example 2

Input

nums = [7,1,3]

Output

[7,1,3]

Explanation

Each element already has one digit, so the result is the same sequence.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.