Notice
Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- ARC
- 앱의생명주기
- Di
- RC
- algorithm
- 반응형프레임워크
- RxSwift
- AutoLayout
- unittest
- Swift코딩테스트
- ReactorKit UnitTest
- alamofire
- Safari Inspector
- firebase
- HackersRank
- Swift디자인패턴
- ios면접
- UIKit
- firestore
- SWIFT
- TDD
- IOS
- 코딩테스트입문
- Bubble Search
- hackerrank
- 카카오맵클론
- iOS앱 디버깅
- 프로그래머스
- 시험에자주나오는것만
- mrc
Archives
- Today
- Total
샘성의 iOS 개발 일지
[Warm Up] Birthday Cake Candles 본문
728x90
문제 설명:
You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.
내 풀이:
// should return the number of tallest candle they have
func birthdayCakeCandles(candles: [Int]) -> Int {
// 큰 순서대로 배열 sorted 후, 첫번째 인덱스의 값 추출 (가장 큰 값)
var height = candles.sorted(by: >)[0]
// 가장 큰 값인 candle만 filter하여 배열에 담은 후, 배열의 요소 갯수 count
return candles.filter { $0 == height }.count
}
728x90
'Algorithm > HackerRank' 카테고리의 다른 글
[Implementation] Apple and Orange (0) | 2023.05.12 |
---|---|
[Implementation] Grading Students (0) | 2023.05.12 |
[Warm Up] Time Conversion (0) | 2023.05.11 |
[Warm Up] Staircase (0) | 2023.05.11 |
[Warm Up] Diagonal Difference (0) | 2023.05.11 |