Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<char> c = GetDuplicates("Hiii").ToList();
- for (int i = 0; i < c.Count; i++)
- {
- Console.WriteLine(c[i]);
- }
- Console.Read();
- }
- public static List<char> GetDuplicates(string text)
- {
- List<char> duplicates = new List<char>();
- char[] chars = text.ToLower().ToCharArray();
- for (int i = 0; i < chars.Length; i++)
- {
- char current = chars[i];
- if (i + 1 >= chars.Length)
- if (duplicates.Contains(current))
- {
- duplicates.Add(current);
- break;
- }
- for (int j = i + 1; j < chars.Length; j++)
- {
- if (current == chars[j] || duplicates.Contains(current))
- {
- duplicates.Add(current);
- break;
- }
- }
- }
- return duplicates;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement