문제
내 정답 코드
import Foundation
func solution(_ arr:[String]) -> String {
var result = ""
for ch in arr {
result += ch
}
return result
}
#
반복문을 사용하여 처리했는데 문제의 의도는 따로 있었다.
joined라는 기술을 알려주기 위해 만들어진 문제인 것 같다.
import Foundation
func solution(_ arr:[String]) -> String {
return arr.joined()
}
배운 기술
1. joined()
https://developer.apple.com/documentation/swift/array/joined()
joined() | Apple Developer Documentation
Returns the elements of this sequence of sequences, concatenated.
developer.apple.com
2. joined(separator: )
https://developer.apple.com/documentation/swift/array/joined(separator:)-5do1g
joined(separator:) | Apple Developer Documentation
Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.
developer.apple.com
'프로그래머스 (Swift) > 기초' 카테고리의 다른 글
[Day3-4] 더 크게 합치기 (0) | 2024.01.21 |
---|---|
[Day3-3] 문자열 곱하기 (0) | 2024.01.21 |
[Day3-1] 문자열 섞기 (0) | 2024.01.21 |
[Day2-5] 문자열 겹쳐쓰기 (0) | 2024.01.14 |
[Day1-4] 대소문자 바꿔서 출력하기 (0) | 2024.01.14 |