#2442
Count Number of Distinct Integers After Reverse Operations
pupil · 430 · lc medium +25 · verified · 81.3% accepted · 743 likes · top 93%
Description
You are given an array nums of positive integers. For each element, reverse its decimal digits and append the resulting number to the end of the array. (Apply this to the original elements only.)
Return the count of distinct integers in the final array.
Example 1:
Input: nums = [1,13,10,12,31]
Output: 6
Explanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].
The reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.
The number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).
Example 2:
Input: nums = [2,2,2]
Output: 1
Explanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].
The number of distinct integers in this array is 1 (The number 2).
Code
1
2
3