Skip to content

[Algorithm] FrogJmpΒ #131

Description

@hwangJi-dev

πŸ’¬Β λ¬Έμ œ

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


πŸ’¬Β Idea

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

πŸ’¬Β ν’€μ΄

import Foundation
publicfunc solution(X :Int, Y :Int, D :Int)->Int{letjmp=(Y - X)/ D
return(Y - X)% D !=0? jmp +1: jmp
}

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

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

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

Activity

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions