最少次数吗,我卡百分之90了 // 用于存储次数 private List<Long> list = new ArrayList<>(); public long GetMinCalculateCount(long sourceX, long sourceY, long targetX, long targetY) { // write code here if(targetX==0||targetY==0){ return -1; } getCount(sourceX,sourceY,targetX,targetY,0L); if(list.size()<1){ return -1; } Collections.sort(list); return list.get(0); } public void getCount(long sourceX, long sourceY, long targetX, long targetY,Long needCount){ if(sourceX>targetX||sourceY>targetY){ return; } if(sourceX==targetX&;&;sourceY==targetY){ list.add(needCount); } getCount(sourceX*2,sourceY*2,targetX,targetY,needCount+1); getCount(sourceX+1,sourceY+1,targetX,targetY,needCount+1); }
点赞 11

相关推荐

头像
01-29 18:11
海南大学 Java
奔跑的suechil...:单从项目看这个简历不怕被问穿吗 带微服务的项目需要相当多的项目理解和经验诶
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务