Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<char> c = GetDuplicates("Hiii").ToList();
  14.             for (int i = 0; i < c.Count; i++)
  15.             {
  16.                 Console.WriteLine(c[i]);
  17.             }
  18.             Console.Read();
  19.         }
  20.  
  21.         public static List<char> GetDuplicates(string text)
  22.         {
  23.             List<char> duplicates = new List<char>();
  24.             char[] chars = text.ToLower().ToCharArray();
  25.  
  26.             for (int i = 0; i < chars.Length; i++)
  27.             {
  28.                 char current = chars[i];
  29.  
  30.                 if (i + 1 >= chars.Length)
  31.                     if (duplicates.Contains(current))
  32.                     {
  33.                         duplicates.Add(current);
  34.                         break;
  35.                     }
  36.                 for (int j = i + 1; j < chars.Length; j++)
  37.                 {
  38.                     if (current == chars[j] || duplicates.Contains(current))
  39.                     {
  40.                         duplicates.Add(current);
  41.                         break;
  42.                     }
  43.                 }
  44.             }
  45.  
  46.             return duplicates;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement