Placido_GDD

pairsOfgloves

Jun 16th, 2022 (edited)
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. public class Kata {
  4.   public static int NumberOfPairs(string[] gloves) {
  5.    
  6.    
  7.     int pairCounter = 0;
  8.     List<string> glovesList = new List<string>(gloves);
  9.    
  10.     for(int x = 0;x < glovesList.Count;x++)
  11.     {
  12.       for(int y = x + 1;y < glovesList.Count;y++)
  13.       {
  14.         if(glovesList[y] == glovesList[x])
  15.         {
  16.           glovesList.RemoveAt(glovesList.IndexOf(glovesList[y]));
  17.          
  18.           pairCounter++;
  19.         }
  20.       }
  21.       glovesList.RemoveAt(glovesList.IndexOf(glovesList[x]));
  22.     }
  23.    
  24.    
  25.    
  26.    
  27.     return pairCounter;
  28.   }
  29. }
Add Comment
Please, Sign In to add comment