#159994
๐ Question ?
https://school.programmers.co.kr/learn/courses/30/lessons/159994
class Solution {
fun solution(cards1: Array<String>, cards2: Array<String>, goal: Array<String>): String {
var answer: String = ""
return answer
}
}
๐งฉ Thought Process
- card1๊ณผ card2์ ์ฒซ๋ฒ์งธ ์๋ฃํ๋ถํฐ ์ฐจ๊ทผ์ฐจ๊ทผ goal ์ ์ฒซ๋ฒ์งธ ์๋ฃํ๊ณผ ๋น๊ตํด ์ค๋ค.
- ๋ง๋ ์๋ฃํ์ ์ธ๋ฑ์ค๋ฅผ 1๋งํผ ์ฌ๋ ค์ค๋ค.
- ๋ง์ฝ ๋๋ค ๋ฌธ์์ด์ด ์ผ์นํ์ง ์๋๋ค๋ฉด No ๋ฌธ์์ด์ ๋ฆฌํดํด์ค๋ค.
๐ Answer
class Solution {
fun solution(cards1: Array<String>, cards2: Array<String>, goal: Array<String>): String {
var answer: String = ""
var n = 0
var m = 0
for (i in goal.indices) {
if (goal[i] == cards1[n]) {
n = checkRange(n, cards1.size)
} else if (goal[i] == cards2[m]) {
m = checkRange(m, cards2.size)
} else {
return "No"
}
}
return "Yes"
}
fun checkRange(n: Int, m: Int): Int {
if (n<m-1) {
return n+1
} else {
return 0
}
}
}
๐ Result
๐ Comment
'Algorithm > Kotlin' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ๋ชจ์๊ณ ์ฌ ์์ ํ์ #42840 (0) | 2023.12.27 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] 2016๋ #12901 (0) | 2023.12.19 |
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ๋ช ์์ ์ ๋น(1) #138477 (0) | 2023.12.14 |
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ์ฝ๋ผ ๋ฌธ์ #132267 (0) | 2023.12.13 |
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ํธ๋ ํ์ดํธ ๋ํ #134240 (0) | 2023.12.12 |