Hi, this time I want to share a simple algorithm.
I found this exercise practicing some algorithm concepts and I think it could help to learn about HashSet in C#.
We can check if a number is a duodigit in C# by converting it to a string and then creating a set of its characters. If the size of the set is less than or equal to two, then the number is a duodigit.
Here’s an example of how we can check if a number is a duodigit in C#:
public static bool IsDuodigit(int num) { return new HashSet<char>(num.ToString()).Count <= 2; }
I hope it could help to you to understand how to use HashSet.
Don’t forget to check my previous post
How to check if number is a DuoDigit C#