@@ -186,6 +186,23 @@ private static string GetAlphabeticString(string message)
186
186
return alphabeticMessageString ;
187
187
}
188
188
189
+ private static bool CheckIfArrayContainsDuplicatedElements ( int [ ] inputArray )
190
+ {
191
+ if ( inputArray == null || inputArray . Length == 0 )
192
+ throw new ArgumentNullException ( nameof ( inputArray ) , "inputArray needs to have elements" ) ;
193
+
194
+ var hashSet = new HashSet < int > ( ) ;
195
+ foreach ( var element in inputArray )
196
+ {
197
+ if ( hashSet . Contains ( element ) )
198
+ {
199
+ return true ;
200
+ }
201
+ hashSet . Add ( element ) ;
202
+ }
203
+ return false ;
204
+ }
205
+
189
206
[ Test ]
190
207
public void RemoveDuplicatesFromSortedArray_1 ( )
191
208
{
@@ -312,5 +329,17 @@ public void ValidPalindrome_22()
312
329
//then
313
330
Assert . AreEqual ( true , isPalindrome ) ;
314
331
}
332
+
333
+ [ Test ]
334
+ [ TestCase ( new [ ] { 0 , 1 , 2 , 4 , 4 , 5 , 7 } , true ) ]
335
+ [ TestCase ( new [ ] { 0 , 1 , 2 , 4 , 5 , 7 } , false ) ]
336
+ public void ContainsDuplicates_82 ( int [ ] inputArray , bool isDuplicateElement )
337
+ {
338
+ //given
339
+ //when
340
+ var isPalindrome = CheckIfArrayContainsDuplicatedElements ( inputArray ) ;
341
+ //then
342
+ Assert . AreEqual ( isDuplicateElement , isPalindrome ) ;
343
+ }
315
344
}
316
345
}
0 commit comments