-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
fun solution(s: String): Int { | ||
var answer = 0 | ||
|
||
val target = s + s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 붙여주는거 괜찮네요!!
* - 트러블 슈팅 | ||
* | ||
*/ | ||
class `전현수_후위_표기식` { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
덕분에 어떻게 풀어야하는지 배웠습니다!!
// 좌 상 우 | ||
private val dirs = listOf( | ||
Position(0, -1), | ||
Position(-1, 0), | ||
Position(0, 1), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방향을 우선순위대로 설정하신 게 깔끔해보였어요!!
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
적이 내려오는 게 아니라 궁수를 올리는 게 적을 내리는 연산을 할 필요도 없고 똑똑하네요
'(' -> { | ||
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스위치문을 이용하니 뭔가 우선순위가 시각적으로 보여지는 느낌이라 좋았어요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확실히 조건이 여러 개니 스위치가 깔끔해 보이네요!👍
// 좌 상 우 | ||
private val dirs = listOf( | ||
Position(0, -1), | ||
Position(-1, 0), | ||
Position(0, 1), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
공감합니다!
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)) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 bfs
풀 생각은 못했는데 설명 들어서 좋았습니다!!
'(' -> { | ||
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확실히 조건이 여러 개니 스위치가 깔끔해 보이네요!👍
📌 from issue #271 📌
📋문제 목록📋
📍추가로 해결한 문제📍
📝메모
공유하고 싶은 정보, 새롭게 알게된 것, 문제를 풀면서 발생한 에로사항 등...자유롭게!