![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
面试代码总结
intimexy
这个作者很懒,什么都没留下…
展开
-
时间复杂度为n的排序代码
public int[] arraysort(int[] a) { int[] num = new int[100000]; for(int i = 0;i < a.length;i++) { num[a[i]]++; } for(int i = 1;i < num.length;i++) { num[i] += num[i - 1]; } int[] b = new int[a.length]; for(int i = b.length - 1; i .原创 2020-12-09 13:44:15 · 793 阅读 · 0 评论 -
非递归前序遍历二叉树,非递归中序遍历二叉树,非递归后续遍历二叉树
import java.util.Stack;public class Front { //非递归前序遍历 public void front(TreeNode node) { Stack<TreeNode> stack = new Stack<>(); stack.push(node); while(!stack.isEmpty()) { TreeNode newnode = stack.pop(); System.out.println(newno原创 2020-11-24 16:45:27 · 511 阅读 · 0 评论 -
java实现Dijkstra算法
1 问题描述 何为Dijkstra算法?Dijkstra算法功能:给出加权连通图中一个顶点,称之为起点,找出起点到其它所有顶点之间的最短距离。 Dijkstra算法思想:采用贪心法思想,进行n-1次查找(PS:n为加权连通图的顶点总个数,除去起点,则剩下n-1个顶点),第一次进行查找,找出距离起点最近的一个顶点,标记为已遍历;下一次进行查找时,从未被遍历中的顶点寻找距离起点最近的一个顶点, 标记为已遍历;直到n-1次查找完毕,结束查找,返回最终结果。 2 解决方案 2.1 使用Dijkstra算法得到转载 2020-11-21 19:10:18 · 181 阅读 · 0 评论 -
链表K个元素进行翻转
public class K { public Node reverseKGroup(Node head, int k) { Node node = new Node(); node.next = head; Node pre = node; Node end = node; while(end != null){ for(int i = 0;i < k && end !=原创 2020-10-18 19:31:13 · 103 阅读 · 0 评论 -
链表相邻元素转换位置
输入:12345输出:21435public class LIANBIAOXIANGLINFANZHUAN { public static void main(String[] args) { Node node1 = new Node(1); Node node2 = new Node(2); Node node3 = new Node(3); Node node4 = new Node(4); Node node5 = new Node(5); node1.next原创 2020-10-18 18:07:56 · 114 阅读 · 0 评论 -
单链表逆序
public class DANLIANBIAONIXU { public static Node reverse(Node head) { Node curnode = head; Node newnode = null; Node oldnode = null; while(curnode != null) { oldnode = curnode.next; curnode.next = newnode; newnode = curnode; curnode原创 2020-10-18 18:05:03 · 61 阅读 · 0 评论 -
找出数组中大于左边所有的数值并小于右边所有的数值的数字
定义一个数组temp来保留从数组右侧索引位置开始的每个索引位置的最小值(从最右侧的索引位置到当前索引位置的最小元素);然后从传入数组arr的左侧遍历数组,判断当前位置的元素是否大于记录的最大元素,大于的话就记录这个元素,并判断是否小于temp数组中当前索引位置+1的元素,把满足条件的数字输出。public class BigThanLSmallThanR { public static void main(String[] args) { int[] arr = {1,8,6,9,10,15,12,原创 2020-10-14 18:45:40 · 1593 阅读 · 0 评论 -
二分查找
public class ERFENCHAZHAO { public static void main(String[] args) { int[] num = {1,3,5,7,9,2,4,6,8,10}; System.out.println(er(num,3)); System.out.println(er(num,20)); } public static int er(int[] num,int val) { int high = num.length - 1; int原创 2020-10-14 18:19:07 · 48 阅读 · 0 评论 -
两个大数相加
两个大数相加两个大数相加。1、是整数;2、两个数无限大,long都装不下;3、不能用BigInteger;4、不能用任何包装类提供的运算方法;5、两个数都是以字符串的方式提供。两个字符串的数字,怎么相加?其实也简单,核心点考的是ASCII码和相加进位的问题。比喻字符类型的'9'怎么转换成int的9?'9' - '0' = 9。这个算法能理解吗?char类型进行算数运算时是不是自动转...转载 2020-10-13 18:41:59 · 327 阅读 · 0 评论 -
一些常见的排序算法代码
冒泡排序主要思想是比较相邻元素的大小,每次循环都把最大的元素放在最后面public class MAOPAO { public static void main(String[] args) { int[] num = {1,3,5,7,9,2,4,6,8,10}; for(int i = 0;i < num.length - 1;i++) { for(int j = i+ 1;j < num.length;j++) { if(num[j] < num[i])原创 2020-10-13 18:34:57 · 120 阅读 · 0 评论