快手工程B笔试

第1、3题AC,第二题70%
第一题是LeetCode上第72题
第二题用的很蠢很蠢的方法
第三题其实比第一题简单,并不需要用dp,代码如下:

import java.util.LinkedList;
import java.util.Scanner;

public class Main3 {
    public static int minOpe(int target, int n, LinkedList<Integer> list) {
        int size = list.size();
        Integer item;
        while (size > 0) {
            item = list.removeFirst();
            if (item == target) {
                return n;
            } else {
                list.offerLast(item + 1);
                list.offerLast(item - 1);
                list.offerLast(item * 2);
                size--;
            }
        }
        return minOpe(target, n + 1, list);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        LinkedList<Integer> list = new LinkedList<>();
        String[] split = str.split(",");
        Integer target = Integer.valueOf(split[1]);
        list.add(new Integer(split[0]));
        System.out.println(minOpe(target, 0, list));
    }
}

能不能进面看天意吧。。。

#快手##笔试题目##题解##春招#
全部评论
第一题经典题目 第二题可以二分解决,代码见下面 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); sc.useDelimiter("[ \n]"); int times = sc.nextInt(); System.out.println(calc(1, times)); } private static long calc(long begin, long end) { long ans = 1; if (begin - end > 10) { return calc(begin, end / 2) * calc(end / 2 + 1, end); } for (long i = begin; i <= end; i++) { long temp = i; while (temp % 10 == 0) { temp /= 10; } ans *= temp; ans %= 1_000_000_000; while (ans % 10 == 0) { ans /= 10; } } return ans % 10; } } 第三题分情况然后动态规划
点赞 回复
分享
发布于 2019-04-13 17:17
又是枚举...真的牛皮。我咋没想到数据量100也不大
点赞 回复
分享
发布于 2019-04-13 17:05
阅文集团
校招火热招聘中
官网直投

相关推荐

点赞 9 评论
分享
牛客网
牛客企业服务