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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 4ms, memory 15.1MB, accepted 2025-12-27.
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;
}
};