일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 세팔
- 세팔로투스
- 산책묘
- 반려동물
- 끈끈이주걱
- CountDiv
- Wall-E
- 고양이 산책
- UIAlertView setFrame
- 고양이
- paper-replika
- 종이모형
- 아기고양이
- 실생묘
- creative park
- PassingCars
- Blueberry
- ios
- 식충식물
- paper craft
- cephalotus
- 애완동물
- 스파르탄
- 태그를 입력해 주세요.
- 명랑이
- 끄니
- UIAlertView addSubView
- 블루베리
- codility
- objective-c
Archives
- Today
- Total
꼼시월드
[codility] Binary Gap 본문
/// max binary gap 구하기
func maxBinaryGap(_ input: Int) -> Int {
let binaryString = String(input, radix: 2)
print("[input] \(binaryString)")
var maxGap: Int = 0
var gapCounter: Int = 0
binaryString.forEach {
if $0 == "1" {
if gapCounter != 0 {
maxGap = max(maxGap, gapCounter)
}
gapCounter = 0
} else {
gapCounter += 1
}
}
print ("[result] \(maxGap)")
return maxGap
}
maxBinaryGap(2)
maxBinaryGap(529)
maxBinaryGap(1041)
결과
[input] 10
[result] 0
[input] 1000010001
[result] 4
[input] 10000010001
[result] 5
'iOS' 카테고리의 다른 글
[codility] CountDiv (3) | 2015.06.10 |
---|---|
[codility] Task name: PassingCars (0) | 2015.06.10 |
UIAlertView addSubView ios7 (0) | 2014.01.29 |
중첩된 딕셔너리의 키를 이용하여 정렬하기 (0) | 2014.01.24 |
ios 기기의 회전 값 구하기 (0) | 2014.01.21 |
Comments