We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💬 문제
https://school.programmers.co.kr/learn/courses/30/lessons/42579
💬 Idea
💬 풀이
import Foundation struct Music { var genre: String var playCnt: Int var index: Int } func solution(_ genres:[String], _ plays:[Int]) -> [Int] { var genreDict: [String: Int] = [:] var musics: [Music] = [] var album: [Int] = [] for (idx, genre) in genres.enumerated() { musics.append(Music(genre: genre, playCnt: plays[idx], index: idx)) if genreDict[genre] == nil { genreDict[genre] = plays[idx] } else { genreDict[genre]! += plays[idx] } } musics = musics.sorted(by: { if $0.playCnt == $1.playCnt { return $0.index < $1.index } else { return $0.playCnt > $1.playCnt } }) for i in genreDict.sorted(by: { $0.value > $1.value }) { let music = musics.filter({ $0.genre == i.key }).map({ $0.index }) if music.count >= 2 { album += music[0...1] } else { album.append(music[0]) } } return album }
소요시간 : 23분
소요시간
💬 더 나은 방법?
struct Music { var playCnt: Int var index: Int } func solution(genres:[String], plays:[Int]) -> [Int] { var genreDict: [String: ([Music], Int)] = [:] var album: [Int] = [] for (idx, genre) in genres.enumerated() { if genreDict[genre] != nil { genreDict[genre]!.0.append(Music(playCnt: plays[idx], index: idx)) genreDict[genre]!.1 += plays[idx] } else { genreDict[genre] = ([Music(playCnt: plays[idx], index: idx)], plays[idx]) } } for i in genreDict.sorted(by: { $0.value.1 > $1.value.1 }) { let music = i.value.0.sorted(by: { return ($0.playCnt == $1.playCnt) ? $0.index < $1.index : $0.playCnt > $1.playCnt }).map({ $0.index }) album += music.count >= 2 ? music[0...1] : [music[0]] } return album }
The text was updated successfully, but these errors were encountered:
#197 - 베스트앨범 문제 풀이
67f13ef
hwangJi-dev
No branches or pull requests
💬 문제
https://school.programmers.co.kr/learn/courses/30/lessons/42579
💬 Idea
💬 풀이
소요시간
: 23분💬 더 나은 방법?
The text was updated successfully, but these errors were encountered: