笔试题解答
/** * @author shishusheng * @date 2018/8/22 23:35 */ import java.util.ArrayList; public class ReverseList { private class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } } ArrayList<Integer> arrayList = new ArrayList<>(); public ArrayList<Integer> printListFromTailToHead(ListNode listNode) { if(listNode != null){ this.printListFromTailToHead(listNode.next); arrayList.add(listNode.val); } return arrayList; } }
显然是斐波那契数列
/** * @author shishusheng * @date 2018/8/22 23:35 */ import java.util.ArrayList; public class JumpFloor { public int JumpFloorII(int N) { int[] stepArr = new int[N]; stepArr[0] = 1; for (int i = 1; i < N; i++) { for (int j = 0; j < i; j++) { stepArr[i] += stepArr[j]; } stepArr[i]+=1; } return stepArr[N - 1]; } }
/** * @author shishusheng * @date 2018/8/22 23:35 */ public class JudgeTriAngle { public String judgeTriAngle(int a, int b, int c) { if (a + b > c && b + c > a && c + a > b) { return "成立"; } return "不成立"; } }
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * @author shishusheng * @date 2018/8/22 23:35 */ public class HourseRun { private class Point { private int x; private int y; private int shortest; public Point() { } public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public int getShortest() { return shortest; } public void addShortest(Point point) { this.shortest = point.getShortest() + 1; } } private static final int MAX_SIZE = 8; private static final int MIN_SIZE = 1; private Point start; private Point end; private List<Point> direction = new ArrayList<>(); private LinkedList<Point> unVisitedPoint = new LinkedList<>(); private int[][] markVisited = new int[9][9]; public HourseRun(Point start, Point end) { this.start = start; this.end = end; init(); } public void init() { direction.add(new Point(2, 1)); //right up horizontal direction.add(new Point(2, -1)); //right down horizontal direction.add(new Point(1, -2)); //right down vertical direction.add(new Point(-1, -2)); //left down vertical direction.add(new Point(-2, -1)); //left down horizontal direction.add(new Point(-2, 1)); //left up horizontal direction.add(new Point(-1, 2)); //left up vertical direction.add(new Point(1, 2)); //right up vertical } private int bfs() { Point current = new Point(); while (!unVisitedPoint.isEmpty()) { current = unVisitedPoint.poll(); markVisited[current.getX()][current.getY()] = 1; if (current.getX() == end.getX() && current.getY() == end.getY()) { break; } for (Point aDirection : direction) { Point next = new Point(current.getX() + aDirection.getX(), current.getY() + aDirection.getY()); next.addShortest(current); if (next.getX() < MIN_SIZE || next.getX() > MAX_SIZE || next.getY() < MIN_SIZE || next.getY() > MAX_SIZE) { continue; } if (markVisited[next.getX()][next.getY()] == 0) { unVisitedPoint.add(next); } } } return current.getShortest(); } public int find() { this.unVisitedPoint.add(start); return bfs(); } }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
设计模式: Java中的工厂设计模式
原文链接 https://github.com/shellhub/blog/issues/22 前言 工厂设计模式(Factory Design Pattern)属于创建模式之一,工厂设计模式在JDK,Spring,Stuts被广泛使用 factory-design-pattern 当一个类或者接口有多个子类,并且基于输入返回特定的子类,此时会使用工厂设计模式。这种模式负责从客户端到工厂类的实例化。 让我们首先学习如何在java中实现工厂设计模式,然后我们将研究工厂模式的优势,我们将在JDK中看到一些工厂设计模式的使用。请注意,此模式也称为工厂方法设计模式。 工厂设计模式: 超类 工厂设计模式中的超类可以是接口,抽象类或普通的java类。对于我们的工厂设计模式示例,我们使用带有重写的toString()方法的抽象超类进行测试。 package com.github.shellhub.model; public abstract class Computer { public abstract String getRAM(); public abstract String getHDD(...
- 下一篇
Confluence 6 Windows 中以服务方式自动重启为服务手动安装 Confluence 分发包
在 Windows: 打开一个命令输入框,然后修改目录到<CONFLUENCE-INSTALL>/bin目录中。 你需要以管理员权限运行这个命令行输入框(Run as administrator),这样你才能够完成下面的步骤: 使用下面的命令来确定 JAVA_HOME 变量被设置到 JDK base 目录: echo %JAVA_HOME% 如果你现在安装的 Java 环境为 JRE(Java Runtime Environment)或者使用的是 Confluence 安装器,替换JAVA_HOME为JRE_HOME。请参考Setting the JAVA_HOME Variable in Windows页面获得更多信息。 请注意,在任何目录路径中的文件夹是以空格为分割符的话(例如,C:\Program Files必须转换为 8 个字符等价的字符串,需要转换为C:\Progra~1)。 在默认的设置中,使用下面的命令来安装服务: service.batinstall Confluence 服务的名字将会被命名为Atlassian Confluence同时将会默认被配置为自动...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker安装Oracle12C,快速搭建Oracle学习环境
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- CentOS7,8上快速安装Gitea,搭建Git服务器
- CentOS关闭SELinux安全模块
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS7设置SWAP分区,小内存服务器的救世主
- Hadoop3单机部署,实现最简伪集群
- CentOS6,7,8上安装Nginx,支持https2.0的开启