有赞笔试——编程题AC

https://www.liaochuntao.cn/2019/08/20/leetcode-29/#leetcode##有赞##笔试题目#
全部评论
点赞 回复
分享
发布于 2019-08-20 16:29
太强了吧,还能try catch
点赞 回复
分享
发布于 2019-08-20 16:31
阅文集团
校招火热招聘中
官网直投
大佬
点赞 回复
分享
发布于 2019-08-20 16:37
楼主,问个问题,第一题可以直接处理数组数据的吗?可以不构建链表的?
点赞 回复
分享
发布于 2019-08-20 16:37
大佬厉害
点赞 回复
分享
发布于 2019-08-20 16:39
请问这是什么神仙?
点赞 回复
分享
发布于 2019-08-20 16:59
package youzan; import java.util.Scanner; public class Main1 {     public static void main(String []args) {         Scanner sc = new Scanner(System.in);         int n = sc.nextInt();         int arr[] = new int[n];         for(int i=0;i<n;i++){             arr[i] = sc.nextInt();         }         int max = 0;         int index = 0;         for(int i=1;i<n-1;i++){            if(Math.abs(arr[i]-arr[n-1])>max){                max = Math.abs(arr[i]-arr[n-1]);                index = i;            }         }         int sum = 0;         for(int i =1;i<n-1;i++){             if(index==i){                 sum+=Math.abs(arr[i+1]-arr[i-1]);                 continue;             }            sum+=Math.abs(arr[i+1]-arr[i]);         }         System.out.println(sum);     } } 我们代码相似度高的吓人
点赞 回复
分享
发布于 2019-08-20 17:40
还是强啊
点赞 回复
分享
发布于 2019-08-20 17:47
第二道题存在问题,由于测试用例的原因导致AC了!我去修正下
点赞 回复
分享
发布于 2019-08-20 17:50
public class ExamTwo {     public static void main(String[] args) {         Scanner scanner = new Scanner(System.in); //        int cnt = Integer.parseInt(scanner.nextLine()); //        String s = scanner.nextLine();         String s = "1,-1,7,3";         String[] ss = s.split(",");         int[] array = new int[ss.length];         for (int i = 0; i < ss.length; i ++) {             array[i] = Integer.parseInt(ss[i]);         }         func(array);     }     public static void func(int[] array) {         int maxDis = Integer.MIN_VALUE;         int totalDis = 0;         // 计算如果不去掉点的实际路程         for (int i = 1; i < array.length; i ++) {             totalDis += Math.abs(array[i] - array[i - 1]);         }         // 获取一个点,假设有A, B, C三个点,||AB| + |BC| - |AC||,其结果为0 or 正数,         // 而这个正数就是进过B点所要多走的路程         for (int i = 1; i + 1 < array.length; i ++) {             maxDis = Math.max(maxDis, Math.abs(array[i] - array[i - 1]) + Math.abs(array[i + 1] - array[i]) - Math.abs(array[i + 1] - array[i - 1]));         }         System.out.println(totalDis - maxDis);     } }
点赞 回复
分享
发布于 2019-08-20 18:05

相关推荐

3 7 评论
分享
牛客网
牛客企业服务