LeetCode Entry
2553. Separate the Digits in an Array
LIst of numbers to list of digits
2553. Separate the Digits in an Array easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1356
Problem TLDR
LIst of numbers to list of digits
Intuition
Convert to strings or do %10 with LInkedList/ArrayDeque or do the reverse.
Approach
- Kotlin: joinToString converts numbers to strings
- Rust: use flat_map or to_string/bytes
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(n)\)
Code
fun separateDigits(n: IntArray) =
n.joinToString("").map{it-'0'}
pub fn separate_digits(n: Vec<i32>) -> Vec<i32> {
n.iter().map(|x|x.to_string()).collect::<String>()
.bytes().map(|b|(b-b'0') as i32).collect()
}