-
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
[전현수] - 도시 건설, 괄호 제거, 싸지방에 간 준하, 타일 채우기 #263
Conversation
private fun IntArray.isValid(): Boolean { | ||
for (i in 1 until this.size) { | ||
if (findParent(i, this) != 1) return false | ||
} | ||
return true | ||
} | ||
|
||
private fun findParent(target: Int, parentInfo: IntArray): Int { | ||
return if (target == parentInfo[target]) target | ||
else findParent(parentInfo[target], parentInfo) | ||
} | ||
|
||
private fun Int.hasSameParent(other: Int, parentInfo: IntArray): Boolean { | ||
return findParent(this, parentInfo) == findParent(other, parentInfo) | ||
} | ||
|
||
private fun union(a: Int, b: Int, parentInfo: IntArray) { | ||
|
||
val aParent = findParent(a, parentInfo) | ||
val bParent = findParent(b, parentInfo) | ||
|
||
if (aParent < bParent) parentInfo[bParent] = aParent | ||
else parentInfo[aParent] = bParent | ||
} |
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 useInfoPq = PriorityQueue<UseInfo>( | ||
Comparator { a, b -> | ||
a.start - b.start | ||
} | ||
) | ||
|
||
val computerPq = PriorityQueue<ComInfo> { a, b -> | ||
a.num - b.num | ||
} | ||
|
||
val usingInfoPq = PriorityQueue<UsingInfo> { a, b -> | ||
a.end - b.end | ||
} |
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.
pq를 여러개 쓰면 너무 복잡할 거 같았는데 오히려 그냥 시뮬레이션 같고 깔끔하네요
} else if (target[i] == ')') { | ||
if (stack.isNotEmpty()) { | ||
parenthesisInfoList.add( | ||
ParenthesisInfo(stack.pop(), i) |
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 useInfoPq = PriorityQueue<UseInfo>( | ||
Comparator { a, b -> | ||
a.start - b.start | ||
} | ||
) | ||
|
||
val computerPq = PriorityQueue<ComInfo> { a, b -> | ||
a.num - b.num | ||
} | ||
|
||
val usingInfoPq = PriorityQueue<UsingInfo> { a, b -> | ||
a.end - b.end | ||
} |
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.
pq 3개 방식이 인상깊었습니다!
for (i in target.indices) { | ||
if (target[i] == '(') { | ||
stack.add(i) | ||
} else if (target[i] == ')') { | ||
if (stack.isNotEmpty()) { | ||
parenthesisInfoList.add( | ||
ParenthesisInfo(stack.pop(), i) |
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 #261 📌
📋문제 목록📋
📍추가로 해결한 문제📍
📝메모
공유하고 싶은 정보, 새롭게 알게된 것, 문제를 풀면서 발생한 에로사항 등...자유롭게!