Skip to content

[Algorithm] OddOccurrencesInArray #130

Description

@hwangJi-dev

💬 문제

https://app.codility.com/programmers/lessons/2-arrays/odd_occurrences_in_array/


💬 Idea

  • 배열의 count를 dictionary에 저장한 다음, 짝수개를 가지는 key를 모두 제거하고 남는 하나의 key를 리턴한다.

💬 풀이

import Foundation
publicfunc solution(B :inout[Int])->Int{varcountDict:[Int:Int]=[:]foriin B {ifcountDict[i]==nil{countDict[i]=1}else{countDict[i]! +=1}}return countDict.filter{ $0.value %2==1}.first!.key
}

소요시간 : 11분

https://app.codility.com/demo/results/training95K8QQ-KYV/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions