1. 数组去重

题目描述

/**
* 有序数组去重
* 输出最终的数字个数
* 输入:1,2,2
* 输出:2
* @author Turing
*
*/

代码

import java.util.*;
public class E {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] str = sc.nextLine().split(",");
int len = str.length;
int [] array = new int[len];
for (int i = 0; i < len; i++) {
array[i] = Integer.valueOf(str[i]);
}
int index = 1;
for (int i = 0; i < len-1; i++) {
if(array[i]!=array[i+1]){
array[index] = array[i+1];
index++;
}
}
System.out.println(index);
}
}

2. 分饼干(分糖果)

题目描述

/**
* 分糖果问题类似
* 分饼干问题,每个孩子至少一个饼干,
* 如果两个孩子坐一起,评分高的孩子必须得到更多的饼干(左右都比较)
* 输出老师购买饼干总数的最小值
* 输入:
6
3
6
3
5
6
2
* 输出:
10
* 说明:第一个数表示孩子数为6;1+2+1+2+3+1=10
*/

代码

import java.util.*;
public class E4 {
public static int m;
public static int n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int[] score = new int[n];
int[] count = new int[n];
for (int i = 0; i < n; i++) {
score[i] = sc.nextInt(); }
Arrays.fill(count, 1);
for(int i=1; i<n; i++){
if (score[i]>score[i-1]) {
count[i]=count[i-1]+1;
}
}
for(int i=n-2; i>=0; i--){
if (score[i]>score[i+1] && count[i]<=count[i+1]) {
count[i]=Math.max(count[i], count[i+1]+1);
}
}
int sum = 0; for (int i = 0; i < count.length; i++) {
sum += count[i];
}
System.out.println(sum); }
}

3. 最小路径和(leetcode64)

题目描述

/**
* 有一个地图,围棋棋盘,两点之间有行走距离起点为左上角,终点为右下角在地图上,
* 每次行走只能沿线移动到移动的临近的点
* 并累加路径计算一个人从地图的起点走到终点的最小路径为多少?
* 输入:
* m*n地图表示如下:
* 3
* 3
* 1 3 4
* 2 1 2
* 4 3 1
* 其中 m=3,n=3表示3*3矩阵
* 行走路径为: 下》右》右》下
* 路径总长:1+2+1+2+1=7
*
* @author Turing
*
*/

代码


import java.util.*;
public class E4 {
public static int m;
public static int n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
m = sc.nextInt();
n = sc.nextInt();
int [][] grid = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
grid[i][j] = sc.nextInt();
}
}
System.out.println(minpath(grid, 0, 0));
}
public static int minpath(int[][]grid, int i,int j){
if(i==m||j==n){
return Integer.MAX_VALUE;
}
if(i==m-1&&j==n-1){
return grid[i][j];
}
return grid[i][j]+Math.min(minpath(grid, i+1, j), minpath(grid, i, j+1));
}
}

58同城笔试题:数组去重;分饼干(分糖果);最小路径和(leetcode64)的更多相关文章

  1. 100 道 Linux 笔试题,能拿 80 分就算大神!

    本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...

  2. 推荐收藏:100道Linux笔试题,能拿90分以上的都去了BAT

    本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统 C. 跟踪管理系统信息和 ...

  3. js面试题-数组去重

    今天,在聊天群里看到数组去重的话题,面试者的答案如下: 参考答案如下: 程序员思维,做出如下测试: 未考虑到:1,‘1’是不同的,应该不去重 未考虑到对象 所以,参考答案只能去重基础类型 根据以往看过 ...

  4. 2019 58同城java面试笔试题 (含面试题解析)

    本人3年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.58同城等公司offer,岗位是Java后端开发,最终选择去了58同城. 面试了很多家公司,感觉大部分公司考察的点 ...

  5. js面试题之数组去重对比

    最近看一些面试题,很多都提到了数组去重,用的最多的不外乎就是下面这个例子 arr.filter(function(value,index,arr){ return arr.indexOf(value, ...

  6. 也许你需要点实用的-Web前端笔试题

    之前发的一篇博客里没有附上答案,现在有空整理了下发出来,希望能帮助到正在找工作的你,还是那句话:技术只有自己真正理解了才是自己的东西,共勉. Web前端笔试题 Html+css 1.对WEB标准以及w ...

  7. C/C++ 笔试题

    /////转自http://blog.csdn.net/suxinpingtao51/article/details/8015147#userconsent# 微软亚洲技术中心的面试题!!! 1.进程 ...

  8. Web前端面试笔试题总结

    最近一段时间要毕业了,忙着找工作,见过不少笔试面试题,自己总结了一些加上网上找的一些整合了一下.答案暂时都东拼西凑出来了,但是还是先不发出来,一方面是答案并不是唯一的并且自己的答案不能保证对,另一方面 ...

  9. 收藏所用C#技术类面试、笔试题汇总

    技术类面试.笔试题汇总 注:标明*的问题属于选择性掌握的内容,能掌握更好,没掌握也没关系. 下面的参考解答只是帮助大家理解,不用背,面试题.笔试题千变万化,不要梦想着把题覆盖了,下面的题是供大家查漏补 ...

随机推荐

  1. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心

    B. Box Permutation p is a sequence of integers p=[p1,p2,-,pn], consisting of n distinct (unique) pos ...

  2. Python程序中的线程操作-守护线程

    目录 一.守护线程 1.1 详细解释 1.2 守护线程例1 1.3 守护线程例2 一.守护线程 无论是进程还是线程,都遵循:守护xx会等待主xx运行完毕后被销毁.需要强调的是:运行完毕并非终止运行. ...

  3. php处理curl的返回结果

    最简单的方式: json_decode($res,true): 结果都是:

  4. IT兄弟连 HTML5教程 介绍HTML5给你认识 习题

    1.关于HTML5说法正确的是:(C) A.HTML5只是对HTML4的一个简单升级 B.所有主流浏览器都支持HTML5 C.HTML5新增了离线缓存机制 D.HTML5主要是针对移动端进行了优化 2 ...

  5. 洛谷 P2657 (数位DP)

    ### 洛谷 P2657 题目链接 ### 题目大意:给你一个数的范围 [A,B] ,问你这段区间内,有几个数满足如下条件: 1.两个相邻数位上的数的差值至少为 2 . 2.不包含前导零. 很简单的数 ...

  6. 纯手打AJAX,还有一个对象转查询字符串的小方法obj=>url

    function json2url(json){ var arr=[]; for(var name in json){ arr.push(name+'='+json[name]); } return ...

  7. wpf file embeded resource is readonly,Copy always will copy the file and its folder to the bin folder

    Wpf file embeded resource will compile the file into the assembly and it will be readonly and can no ...

  8. vs未能正确加载CSharpPackage包,未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”包

    VS2017打开项目时提示未能正确加载CSharpPackage包, 可以使用 devenv命令工具来解决,操作如下 打开vs2017开发人员命令提示符(请使用管理员身份运行),如图 敲入  deve ...

  9. Python中断多重循环的几种思路

    I. 跳出单循环 不管是什么编程语言,都有可能会有跳出循环的需求,比如枚举时,找到一个满足条件的数就终止.跳出单循环是很简单的,比如 for i in range(10): if i > 5: ...

  10. Tomcat8史上最全优化实践

    Tomcat8史上最全优化实践 1.Tomcat8优化 1.1.Tomcat配置优化 1.1.1.部署安装tomcat8 1.1.2 禁用AJP连接 1.1.3.执行器(线程池) 1.1.4 3种运行 ...