https://leetcode.com/problems...HardGoogle,Amazon第一种方案使用BFS//bfspublicintracecar(inttarget){intres=0;队列q=newLinkedList<>();//0:位置,1:速度Setvisited=newHashSet<>();visited.add("0#1");q.offer(newint[]{0,1});while(!q.isEmpty()){intsize=q.size();for(inti=0;i0&&newPos0?-1:1;key=newPos+"#"+newSpeed;如果(!visited.contains(key)&&newPos>0&&newPos0)returndp[target];intn=(int)(Math.log(target)/Math.log(2))+1;//如果是第一种情况target=2^n-1,那么直接把结果放回去if(1<