프로그래머스_가운데 글자 가져오기_깨달은것

hankyulee·2021년 10월 8일
0

Swift coding test 준비

목록 보기
32/57

내코드:

func solution(_ s:String) -> String {
    if s.count % 2 != 0 {return 
    String(s[s.index(s.startIndex,offsetBy:s.count/2)])} 
    else {return("\(s[s.index(s.startIndex,offsetBy:s.count/2-1)])\(s[s.index(s.startIndex,offsetBy:s.count/2)])")}
    
    
    
    
}

깨달은것:

String(s[String.Index(encodedOffset: (s.count-1)/2)...String.Index(encodedOffset: s.count/2)])
  • String.Index(encodedOffset:) 처음 봤다.. 유용한

0개의 댓글