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

[Algorithm] FrogJmp #131

Closed
hwangJi-dev opened this issue Mar 22, 2023 · 0 comments
Closed

[Algorithm] FrogJmp #131

hwangJi-dev opened this issue Mar 22, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Mar 22, 2023

πŸ’¬Β λ¬Έμ œ

https://app.codility.com/programmers/lessons/3-time_complexity/frog_jmp/


πŸ’¬Β Idea

  • λ„λ‹¬ν•˜λ €λŠ” μœ„μΉ˜μ—μ„œ 좜발 μœ„μΉ˜λ₯Ό λΊ€ 거리λ₯Ό 개ꡬ리의 점프 횟수둜 λ‚˜λˆ„μ–΄ 점프 횟수λ₯Ό κ΅¬ν•œλ‹€.
  • 이 λ•Œ λ‚˜λ¨Έμ§€κ°€ λ°œμƒν•˜λŠ” 경우 + 1을 ν•˜μ—¬ λ„λ‹¬ν•˜λ €λŠ” μœ„μΉ˜λ₯Ό λ„˜μ„ 수 μžˆλ„λ‘ ν•΄μ€€λ‹€.

πŸ’¬Β ν’€μ΄

import Foundation

public func solution(X : Int, Y : Int, D : Int) -> Int {
    let jmp = (Y - X) / D
    return (Y - X) % D != 0 ? jmp + 1 : jmp
}

μ†Œμš”μ‹œκ°„ : 7λΆ„

μ‹œκ°„ λ³΅μž‘λ„ : O(1)

ν‰κ°€ν‘œ : https://app.codility.com/demo/results/trainingPYHF59-6U5/

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

No branches or pull requests

1 participant