class Solution {
fun solution(my_string: String, is_prefix: String) =
if(my_string.startsWith(is_prefix)) 1 else 0
}
class Solution {
fun solution(my_string: String, is_prefix: String): Int = if (my_string.startsWith(is_prefix)) 1 else 0
}
startsWith()
접두사인지 확인하려면 startsWith() 메소드를 사용합니다.
설명: 문자열이 특정 접두사로 시작하는지 확인합니다.
반환값: Boolean (true 또는 false)
val text = "HelloWorld"
// "Hello"로 시작하는지 확인
println(text.startsWith("Hello")) // true
// "World"로 시작하는지 확인
println(text.startsWith("World")) // false
이전에 풀었던 문제 중에 접미사인지 확인하는 문제랑 흡사하여 endsWith()메소가 떠올라 그 반대인 startsWith()메소드를 사용해 풀었다.