how to find duplicate values in integer array by loop in swift?
问题 I need to know how to find duplicate values in integer array by loop method in swift? I tried to -> func findDuplicates (array: [Int]) { var prevItem = array[0] for i in 0...array.count-1 { if prevItem == array[i] { print(i) } else { print("there is no any duplicates values") } } } please show my solution in this way! 回答1: You can use a set and every time you try to insert an element it fails it means it is a duplicate. You would need also to make sure you don't keep duplicate elements on the