๋ฐ์ํ
๋ฐฐ์ด ์์์ ๊ธธ์ด
๋ฌธ์ ์ค๋ช
๋ฌธ์์ด ๋ฐฐ์ด strlist๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง๋๋ค. strlist ๊ฐ ์์์ ๊ธธ์ด๋ฅผ ๋ด์ ๋ฐฐ์ด์ retrunํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
์ ํ ์ฌํญ
- 1 ≤ strlist ์์์ ๊ธธ์ด ≤ 100
- strlist๋ ์ํ๋ฒณ ์๋ฌธ์, ๋๋ฌธ์, ํน์๋ฌธ์๋ก ๊ตฌ์ฑ๋์ด ์์ต๋๋ค.
์ ์ถ๋ ฅ ์
strlist | result |
["We", "are", "the", "world!"] | [2, 3, 3, 6] |
["I", "Love", "Programmers."] | [1, 4, 12] |
์ ์ถ๋ ฅ ์ ์ค๋ช
์ ์ถ๋ ฅ ์ #1
- ["We", "are", "the", "world!"]์ ๊ฐ ์์์ ๊ธธ์ด์ธ [2, 3, 3, 6]์ returnํฉ๋๋ค.
์ ์ถ๋ ฅ ์ #2
- ["I", "Love", "Programmers."]์ ๊ฐ ์์์ ๊ธธ์ด์ธ [1, 4, 12]์ returnํฉ๋๋ค.
์ ์ถ
import Foundation
func solution(_ strlist:[String]) -> [Int] {
var answer = [Int]()
for str in strlist{
answer.append(str.count)
}
return answer
}
๋ค๋ฅธ ํ์ด
import Foundation
func solution(_ strlist:[String]) -> [Int] {
return strlist.map({ $0.count })
}
๋ฐ์ํ
'โจ๏ธ Language > swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค LV.0] ์บ๋ฆญํฐ์ ์ขํ (0) | 2023.01.02 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค LV.0] ์ง์ฌ๊ฐํ ๋์ด ๊ตฌํ๊ธฐ (0) | 2022.12.30 |
[ํ๋ก๊ทธ๋๋จธ์ค LV.0] ์ปจํธ๋กค ์ ํธ (0) | 2022.12.30 |
[ํ๋ก๊ทธ๋๋จธ์ค LV.0] ์์ธ์๋ถํด (0) | 2022.12.30 |
[ํ๋ก๊ทธ๋๋จธ์ค LV.0] ์จ์ด์๋ ์ซ์์ ๋ง์ (1) (0) | 2022.12.30 |