Skip to content

Commit 005b6fc

Browse files
authored
Merge pull request MukulCode#452 from Frostyxnova/patch-1
Count Number of Distinct Integers After Reverse Operations(Leetcode C…
2 parents 0f18957 + 1316d8b commit 005b6fc

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Leetcode Contest Question
2+
class Solution {
3+
public int countDistinctIntegers(int[] nums) {
4+
ArrayList<Integer> t = new ArrayList<>();
5+
Set<Integer> set = new HashSet<>();
6+
for(int i:nums){
7+
t.add(i);
8+
}
9+
10+
for(int i:nums){
11+
int revNum = rev(i);
12+
t.add(revNum);
13+
}
14+
15+
for(var i: t){
16+
set.add(i);
17+
}
18+
return set.size();
19+
}
20+
21+
22+
public int rev(int i){
23+
int res = 0;
24+
while(i>0){
25+
res*=10;
26+
res+=i%10;
27+
i/=10;
28+
}
29+
return res;
30+
}
31+
}

0 commit comments

Comments
 (0)