Skip to content

Commit 51bb364

Browse files
committed
add 2442
1 parent ff7f727 commit 51bb364

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

javascript/LeetCode/Array/2442.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 2442. Count Number of Distinct Integers After Reverse Operations
3+
*
4+
* 計算陣列元素digits反轉後,加上原有陣列會有幾個數字是唯一值
5+
*
6+
* @param {number[]} nums
7+
* @return {number}
8+
*/
9+
var countDistinctIntegers = function(nums) {
10+
// O(N)
11+
nums.push(...nums.map(num =>
12+
parseInt(num.toString().split('').reverse().join(''))
13+
));
14+
return new Set(nums).size;
15+
};
16+
let nums = [1,13,10,12,31];
17+
/*
18+
Output: 6
19+
Explanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].
20+
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.
21+
The number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).
22+
*/
23+
console.log(countDistinctIntegers(nums));

javascript/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ var multiply = function (num1, num2) {
147147
// "56088"
148148
const num1 = "123456789",num2 = "987654321";
149149
// "121932631112635269"
150-
console.log(multiply(num1, num2));
150+
// console.log(multiply(num1, num2));ㄋㄋ
151151

152152

153153

0 commit comments

Comments
 (0)