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

25-jung0115 #189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

25-jung0115 #189

wants to merge 1 commit into from

Conversation

jung0115
Copy link
Member

@jung0115 jung0115 commented Nov 27, 2024

πŸ”— 문제 링크

ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ | 그리디 μ•Œκ³ λ¦¬μ¦˜ - ν˜Έν…” λŒ€μ‹€(Lv.2)

ν˜Έν…”μ„ 운영 쀑인 μ½”λ‹ˆλŠ” μ΅œμ†Œν•œμ˜ κ°μ‹€λ§Œμ„ μ‚¬μš©ν•˜μ—¬ μ˜ˆμ•½ μ†λ‹˜λ“€μ„ λ°›μœΌλ €κ³  ν•©λ‹ˆλ‹€. ν•œ 번 μ‚¬μš©ν•œ 객싀은 퇴싀 μ‹œκ°„μ„ κΈ°μ€€μœΌλ‘œ 10λΆ„κ°„ μ²­μ†Œλ₯Ό ν•˜κ³  λ‹€μŒ μ†λ‹˜λ“€μ΄ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
μ˜ˆμ•½ μ‹œκ°μ΄ λ¬Έμžμ—΄ ν˜•νƒœλ‘œ λ‹΄κΈ΄ 2차원 λ°°μ—΄ book_time이 λ§€κ°œλ³€μˆ˜λ‘œ μ£Όμ–΄μ§ˆ λ•Œ, μ½”λ‹ˆμ—κ²Œ ν•„μš”ν•œ μ΅œμ†Œ κ°μ‹€μ˜ 수λ₯Ό return ν•˜λŠ” solution ν•¨μˆ˜λ₯Ό μ™„μ„±ν•΄μ£Όμ„Έμš”.

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

30λΆ„

✨ μˆ˜λ„ μ½”λ“œ

ν•˜λ£¨ 24μ‹œκ°„μ΄ 1440뢄이기 λ•Œλ¬Έμ— 0~1439λΆ„κΉŒμ§€ 각 λΆ„λ§ˆλ‹€ λͺ‡ 개의 객싀이 ν•„μš”ν•œμ§€λ₯Ό μ²΄ν¬ν•΄μ€¬μŠ΅λ‹ˆλ‹€.

μš°μ„  각 μ˜ˆμ•½λ§ˆλ‹€ μ‹œμž‘κ³Ό μ’…λ£Œ μ‹œκ°„μ„ λΆ„λ‹¨μœ„λ‘œ λ³€ν™˜ν•˜κ³ , 10λΆ„μ˜ μ²­μ†Œμ‹œκ°„μ„ 더해 μ’…λ£Œ μ‹œμ μ„ μ‘°μ •ν•΄μ€¬μŠ΅λ‹ˆλ‹€.
λ§Œμ•½ 10λΆ„λΆ€ν„° 30λΆ„κΉŒμ§€ μ΄μš©ν•œλ‹€λ©΄ λ°°μ—΄μ˜ 10번 λ°©λΆ€ν„° 30번 λ°©κΉŒμ§€λ₯Ό 1μ”© μ¦κ°€μ‹œμΌœ 이용 객싀 수λ₯Ό μΉ΄μš΄νŠΈν•΄μ€¬μŠ΅λ‹ˆλ‹€

λͺ¨λ“  μ˜ˆμ•½μ— λŒ€ν•΄ μœ„ λ™μž‘μ„ λ°˜λ³΅ν•œ λ’€, κ°€μž₯ 큰 값을 λ°˜ν™˜ν•΄μ£Όλ©΄ μ΅œλŒ€ 객싀 수λ₯Ό ꡬ할 수 μžˆμŠ΅λ‹ˆλ‹€

βœ… μ΅œμ’… μ½”λ“œ

  fun solution(book_time: Array<Array<String>>): Int {
    val times = IntArray(1440)

    for (time in book_time) {
      var start = time[0].substring(0, 2).toInt() * 60 + time[0].substring(3, 5).toInt()
      var end = time[1].substring(0, 2).toInt() * 60 + time[1].substring(3, 5).toInt()
      
      for (j in start until (end + 10).coerceAtMost(1440)) {
        times[j]++
      }
    }

    return times.maxOrNull() ?: 0
  }
}

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

κ·Έλ™μ•ˆ 정신이 μ—†μ–΄μ„œ 문제 ν‘ΈλŠ” κ±Έ 잊고 μžˆμ—ˆλŠ”λ° λ‹€μ‹œ 차곑차곑 ν’€μ–΄λ³΄κ² μŠ΅λ‹ˆλ‹€!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant