Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[전현수] - 괄호 회전하기, 후위 표기식, 캐슬 디펜스 #272

Merged
merged 4 commits into from
Jun 2, 2024

Conversation

soopeach
Copy link
Member

@soopeach soopeach commented Jun 2, 2024

📌 from issue #271 📌

📋문제 목록📋

괄호 회전하기: ✅
후위 표기식: ⛔️
캐슬 디펜스: ✅

📍추가로 해결한 문제📍

추천: 👍  
비추천: 👎  
문제에 대한 간단한 코멘트를 남겨주셔도 좋을 것 같아요!

📝메모

공유하고 싶은 정보, 새롭게 알게된 것, 문제를 풀면서 발생한 에로사항 등...자유롭게!


@soopeach soopeach requested review from bngsh, jeeminimini and jhg3410 June 2, 2024 10:47
@soopeach soopeach self-assigned this Jun 2, 2024
@soopeach soopeach added the 현수 label Jun 2, 2024
fun solution(s: String): Int {
var answer = 0

val target = s + s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 붙여주는거 괜찮네요!!

* - 트러블 슈팅
*
*/
class `전현수_후위_표기식` {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

덕분에 어떻게 풀어야하는지 배웠습니다!!

Comment on lines +32 to +37
// 좌 상 우
private val dirs = listOf(
Position(0, -1),
Position(-1, 0),
Position(0, 1),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

방향을 우선순위대로 설정하신 게 깔끔해보였어요!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공감합니다!


var curEliminatedCnt = 0

for (archerX in n - 1 downTo 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

적이 내려오는 게 아니라 궁수를 올리는 게 적을 내리는 연산을 할 필요도 없고 똑똑하네요

Comment on lines +25 to +50
'(' -> {
stack.push('(')
}

'*', '/' -> {
while (stack.isNotEmpty()) {
if (stack.peek() == '*' || stack.peek() == '/') sb.append(stack.pop())
else break
}
stack.push(ch)
}

'+', '-' -> {
while (stack.isNotEmpty()) {
if (stack.peek() == '(') break
sb.append(stack.pop())
}
stack.push(ch)
}

')' -> {
while (stack.isNotEmpty()) {
val fromStack = stack.pop()
if (fromStack == '(') break
sb.append(fromStack)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스위치문을 이용하니 뭔가 우선순위가 시각적으로 보여지는 느낌이라 좋았어요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확실히 조건이 여러 개니 스위치가 깔끔해 보이네요!👍

Comment on lines +32 to +37
// 좌 상 우
private val dirs = listOf(
Position(0, -1),
Position(-1, 0),
Position(0, 1),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공감합니다!

Comment on lines +85 to +111
val queue: Queue<Bundle> = LinkedList()

queue.add(Bundle(Position(archerX, curArcherY), 1))

while (queue.isNotEmpty()) {

val (curPos, curRange) = queue.poll()

if (curBoard[curPos.x][curPos.y] == 1) {
targetSet.add(Position(curPos.x, curPos.y))
return@forEach
}

if (curRange < range) {
dirs.forEach dir@{
val nx = curPos.x + it.x
val ny = curPos.y + it.y


if (nx !in 0 until n ||
ny !in 0 until m
) return@dir

queue.add(Bundle(Position(nx, ny), curRange + 1))
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bfs 풀 생각은 못했는데 설명 들어서 좋았습니다!!

Comment on lines +25 to +50
'(' -> {
stack.push('(')
}

'*', '/' -> {
while (stack.isNotEmpty()) {
if (stack.peek() == '*' || stack.peek() == '/') sb.append(stack.pop())
else break
}
stack.push(ch)
}

'+', '-' -> {
while (stack.isNotEmpty()) {
if (stack.peek() == '(') break
sb.append(stack.pop())
}
stack.push(ch)
}

')' -> {
while (stack.isNotEmpty()) {
val fromStack = stack.pop()
if (fromStack == '(') break
sb.append(fromStack)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확실히 조건이 여러 개니 스위치가 깔끔해 보이네요!👍

@soopeach soopeach merged commit 6ac4d09 into main Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants