class Solution { public int solution(int X, int Y, int D) { // write your code in Java SE 8 // if(X > Y || X == Y) return 0; // int steps = 0; // while(Y > X) // { // X+=D; // steps++; // } // return steps; int iStep = 0; if((Y-X)%D == 0) { iStep = (Y-X)/D; }else{ iStep = ((Y-X)/D)+1; } return iStep; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter