Skip to content

Latest commit

 

History

History
17 lines (15 loc) · 366 Bytes

RemoveDuplicatesSolution.md

File metadata and controls

17 lines (15 loc) · 366 Bytes

Remove Duplicates Solution

Swift

func removeDuplicates(from arr: [Int]) -> [Int] {
    var visitedElements = Set<Int>()
    var duplicateFreeArr = [Int]()
    for num in arr {
        if !visitedElements.contains(num) {
            visitedElements.insert(num)
            duplicateFreeArr.append(num)
        }
    }
    return duplicateFreeArr
}