-
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
[소병희] 겹치는 건 싫어, 쉬운 최단거리, 회전 초밥 #169
Conversation
while(p2 < n) { | ||
count[nums[p2]]++ | ||
while(count[nums[p2]] > k && p1 < p2) | ||
count[nums[p1++]]-- | ||
|
||
p2++ | ||
ans = ans.coerceAtLeast(p2 - p1) | ||
} |
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.
엄청 깔끔하게 로직을 작성하셨네요
if (v.toInt() == 2) { | ||
q.add(intArrayOf(i, j, 0)) | ||
ground[i][j] = 0 | ||
} | ||
else if (v.toInt() == 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.
2, 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.
근데 저도 똑같이 했어요 ㅋㅋㅋㅋㅋ
if (nr !in 0 until n || nc !in 0 until m) continue | ||
if (ground[nr][nc] == 0) continue | ||
if (ground[nr][nc] != -1) continue |
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.
묶어두는 것 보다는 관심사(?)가 다르면 떨어트려놓는 것도 괜찮은 방법인 것 같군요!
while(count[nums[p2]] > k && p1 < p2) | ||
count[nums[p1++]]-- |
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.
오호 이렇게도 할 수 있군요
repeat(n) { i -> | ||
readLine().split(" ").forEachIndexed { j, v -> | ||
if (v.toInt() == 2) { | ||
q.add(intArrayOf(i, j, 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.
미리 queue에 넣는게 좋네요
var p1 = 0 | ||
var p2 = 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.
투 포인터!👍
📌 from issue #165 📌
📋문제 목록📋