最少次数吗,我卡百分之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); }