๐ ๋ฌธ์

๐ ๋์ ๋ฌธ์ ํ์ด
class Solution {
fun solution(before: String, after: String): Int {
val newBefore = before.toList().sorted().joinToString("")
val newAfter = after.toList().sorted().joinToString("")
return if(newBefore.equals(newAfter)) 1 else 0
}
}
๐ ๋ค๋ฅธ ์ฌ๋์ ๋ฌธ์ ํ์ด
๋ค๋ฅธ ์ฌ๋์ ๋ฌธ์ ํ์ด๋ ์ข์์ ์๊ฐ ๋๊ฑฐ๋ ๋ง์ ์ฌ๋๋ค์ด ํผ ๋ฐฉ๋ฒ ๊ธฐ์ค์ผ๋ก ์ฒจ๋ถํ์์ต๋๋ค.
class Solution {
fun solution(before: String, after: String): Int =
if (before.toList().sorted() == after.toList().sorted()) 1 else 0
}
๐ ๋ฌธ์ ํ์ด ์ ์๋ฉด ์ข์ ๊ฒ
sorted()
- ๋ฆฌ์คํธ๋ ๋ฐฐ์ด์ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌ
- ๋ฐํ ํ์
: ์๋ก์ด ๋ฆฌ์คํธ (List<T>)
- ์๋ ๋ฆฌ์คํธ๋ฅผ ๋ฐ๊พธ์ง ์๊ณ ์ ๋ ฌ๋ ์ ๋ฆฌ์คํธ๋ฅผ ๋ง๋ค์ด ์ค๋๋ค.
val chars = listOf('b','a','c')
val sortedChars = chars.sorted()
println(sortedChars) // [a, b, c]
๋ฌธ์์ด์ ์ ๋ ฌํ๋ฉด ์๋๊ทธ๋จ ์ฌ๋ถ๋ฅผ ์ฝ๊ฒ ๋น๊ตํ ์ ์์ด์.
๋ฐ์ํ
'android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ๊ฐ๋ฐ์ ๋ฑ๋ก ํ Google Play Console์์ ์ฑ ๋ฑ๋กํ๊ธฐ (0) | 2026.01.12 |
|---|---|
| Module ์์ฑํ๊ธฐ (0) | 2026.01.11 |
| DTO, Entity, Model(Domain, UI)์ ์ฐจ์ด (0) | 2025.12.08 |
| [Compose] Recomposition (1) | 2025.07.13 |
| ๋ฅ๋งํฌ๋? (5) | 2025.06.02 |