[java] 코딜리티 lesson3 FrogJmp

[java] 코딜리티 lesson3 FrogJmp

풀이:

목적지 Y에서 X를 뺀뒤 점프가능한 간격 D로 나누어주었다.

이때 나누어 떨어지면(나머지가 0이면) 그 값이 답이지만 그렇지 않다면 한칸 더 뛰어줘야 하므로 +1

// you can also use imports, for example: // import java.util.*; // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { public int solution(int X, int Y, int D) { if(((Y-X)%D)==0){ return (Y-X)/D; }else{ return (Y-X)/D+1; } } }

from http://sthtoprve.tistory.com/11 by ccl(A) rewrite - 2021-11-11 02:27:56