层级遍历 import java.util.LinkedList; import java.util.Scanner; public class Main {    public static void main(String[] args) {       Scanner in = new Scanner(System.in);       String s = in.next();       String[] split = s.split(",");       int x = Integer.valueOf(split[0]);       int y = Integer.valueOf(split[1]);       LinkedList<Integer> list = new LinkedList<>();       int times = 0;       int count = 0;       int temp = x;       while(temp != y) {           list.add(temp+1);           list.add(temp-1);           list.add(temp*2);           if(count == 0) {               count = list.size();               times++;           }           temp = list.removeFirst();           count--;       }       System.out.println(times);    } }
点赞 1

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务