LeetCode solutions

2639. Separate the Digits in an Array

My accepted C++ solution to LeetCode problem 2639, Separate the Digits in an Array, running in 4ms.

  • Difficulty: Easy
  • C++
  • Runtime 4ms
  • Memory 15.1MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 4ms, memory 15.1MB, accepted 2025-12-27.

cpp
class Solution {
    public:
    vector<int> separateDigits(vector<int>& nums) {
        vector<int> ans;
        for (int num : nums) {
            string s = to_string(num);
            for (char c : s) {
                ans.push_back(c - '0');
            }
        }
        return ans;
    }
};

Source