프로그래머스-이상한 문자 만들기

효딩딩·2023년 12월 20일
0

문제

풀이

func solution(_ s:String) -> String {
    var index = 0
    var result = ""
    
    for i in s {
        
        if i == " " {
            index =  0
            result += " "
        } else {
            if index  % 2 == 0 {
                result += i.uppercased()
                
            } else {
                result += i.lowercased()
                
            }
            index += 1
        }
    }

    return result
}
solution("try hello world")
profile
어제보다 나은 나의 코딩지식

0개의 댓글