#12919
๐ Question ?
https://school.programmers.co.kr/learn/courses/30/lessons/12919
class Solution {
fun solution(seoul: Array<String>): String {
var answer = ""
return answer
}
}
๐งฉ Thought Process
- Kim์ด ์์นํ ์ธ๋ฑ์ค ์ฐพ๊ธฐ
https://www.baeldung.com/kotlin/array-item-position
@Test
fun `Find index using indexOf`() {
val numbers = arrayOf(1, 2, 3, 4, 5)
val elementToFind = 3
val index = numbers.indexOf(elementToFind)
assertEquals(2, index)
}
์ ์์ ๋ฅผ ์ฐธ๊ณ ํ์ฌ ๋ฌธ์ ๋ฅผ ํ์ด์ผ๊ฒ ๋ค.
๐ Answer
class Solution {
fun solution(seoul: Array<String>): String {
var answer = ""
val elementToFind = "Kim"
val index = seoul.indexOf(elementToFind)
return "๊น์๋ฐฉ์ ${index}์ ์๋ค"
}
}
๐ Result
๐ Comment
์ค๋์ ํฐ ์ด๋ ค์์ด ์์๋ ๊ฑฐ ๊ฐ๋ค. ๊ทธ๋๋ ๋ค๋ฅธ ํ์ด ๋ณด๋ฉด์ ๋ฐฐ์ด์ ์ด ์์ด์ ๋คํ์ด๋ค.
'Kotlin > Programmers Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค - ์ฝํ๋ฆฐ] ์์ ๋ํ๊ธฐ #76501 (0) | 2023.10.25 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค - ์ฝํ๋ฆฐ] ๋๋์ด ๋จ์ด์ง๋ ์ซ์ ๋ฐฐ์ด #12910 (0) | 2023.10.25 |
[ํ๋ก๊ทธ๋๋จธ์ค - ์ฝํ๋ฆฐ] ์ฝ๋ผ์ธ ์ถ์ธก #12943 (0) | 2023.10.24 |
[ํ๋ก๊ทธ๋๋จธ์ค - ์ฝํ๋ฆฐ] ๋ ์ ์ ์ฌ์ด์ ํฉ #12912 (0) | 2023.10.24 |
[ํ๋ก๊ทธ๋๋จธ์ค - ์ฝํ๋ฆฐ] ํ์ค๋ ์ #12947 (0) | 2023.10.22 |