博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1. 青蛙跳跳FrogJmp Count minimal number of jumps from position X to Y.
阅读量:5990 次
发布时间:2019-06-20

本文共 1288 字,大约阅读时间需要 4 分钟。

青蛙跳跳;

package com.code;public class Test03_1 {     public int solution(int X, int Y, int D) {        int res = (Y-X)/D+((Y-X)%D==0?0:1);        return res;     }         public static void main(String[] args) {        Test03_1 t03 = new Test03_1();        System.out.println(t03.solution(10, 85, 30));            }}/** A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position  greater than or equal to Y. The small frog always jumps a fixed distance, D.Count the minimal number of jumps that the small frog must perform to reach its target.Write a function:class Solution { public int solution(int X, int Y, int D); }that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.For example, given:  X = 10  Y = 85  D = 30the function should return 3, because the frog will be positioned as follows:after the first jump, at position 10 + 30 = 40after the second jump, at position 10 + 30 + 30 = 70after the third jump, at position 10 + 30 + 30 + 30 = 100Assume that:X, Y and D are integers within the range [1..1,000,000,000];X ≤ Y.Complexity:expected worst-case time complexity is O(1);expected worst-case space complexity is O(1). *  *  * */

 

转载地址:http://nxjlx.baihongyu.com/

你可能感兴趣的文章
css - 选择器语法入门
查看>>
VirtualBox centos 6.5 minimal 开启网络
查看>>
30443数据查询语言DQL
查看>>
java23种设计模式之四:建造者模式
查看>>
[Swust OJ 763]--校门外的树 Plus(暴力枚举)
查看>>
mysql 批量修改字段方法
查看>>
【转】IPV6的地址类型
查看>>
Swap Nodes in Pairs
查看>>
软件项目文档——Responsibility Assignment Matrix
查看>>
数据结构(一)_数组
查看>>
【Android您问我讲】如何使用选显卡 - Tabhost的使用
查看>>
CCF201803-2 碰撞的小球(模拟)
查看>>
Convert CString to ANSI string in UNICODE projects
查看>>
Nuget出现错误怎么办?
查看>>
Kafka
查看>>
C语言中变量的存储类型
查看>>
C++_类和动态内存分配5-使用指向对象的指针
查看>>
代码优化的一个小例子
查看>>
ExtJS的MessageBox总结
查看>>
JAVA循环陷阱-数据溢出
查看>>