Skip to content

[Algorithm] 위장 #31

Description

@hwangJi-dev

💬 문제

[프로그래머스 스쿨 - 온라인 IT 특화 교육 전문 플랫폼](https://school.programmers.co.kr/learn/courses/30/parts/12077)


💬 Idea

  • Dictionary로 옷의 종류별 개수를 저장한 뒤 조합될 수 있는 수를 구하는 수식을 잘 생각하면 쉬웠던 문제였다.
    • 그런데 수로 접근하지 않고, 모든 조합의 경우를 String으로 반환하려 해서 조금 헤매었다.

💬 풀이

func solution(_ clothes:[[String]])->Int{varclothesDict:[String:Int]=[:]forclothin clothes {ifclothesDict[cloth[1]]!=nil{clothesDict[cloth[1]]! +=1}else{clothesDict[cloth[1]]=1}}varresult=1foriin clothesDict.values {
result *=(i+1)}return result -1}

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