摘要: // 使用hash表 public static char getFirstNotRepeat(char[] arr) { if (arr == null || arr.length == 0) { return '\0'; } int tableSize = 256; // 简单的hash表 in 阅读全文
posted @ 2018-01-20 21:39 qingtianBKY 阅读(91) 评论(0) 推荐(0) 编辑
摘要: public static int numOfIntToString(int number) { if (number < 0) { return -1; } if (number > 0 && number <= 9) { return 1; } // 转换成相应的字符串 String strNu 阅读全文
posted @ 2018-01-18 16:28 qingtianBKY 阅读(442) 评论(0) 推荐(0) 编辑
摘要: public class 把数组组成最小的数{ // 使用冒泡排序思想 防止溢出 进行转化成字符串 然后进行比较ab与ba public String getMinCombineNum(int[] arr) { if (arr == null || arr.length == 0) { return 阅读全文
posted @ 2018-01-17 20:28 qingtianBKY 阅读(194) 评论(0) 推荐(0) 编辑
摘要: Java中Comparable和Comparator实现对象比较 目录 一. Comparator二. Comparable三.比较 当需要排序的集合或数组不是单纯的数字型时,通常可以使用Comparator或Comparable,以简单的方式实现对象排序或自定义排序。 A comparison f 阅读全文
posted @ 2018-01-17 15:19 qingtianBKY 阅读(266) 评论(0) 推荐(0) 编辑
摘要: public class 连续子数组的最大和{ // 时间复杂度为O(n) private static int getSubMaxSum(int[] array) { if (array == null || array.length == 0) { return 0; } int sum = 0 阅读全文
posted @ 2018-01-15 15:33 qingtianBKY 阅读(138) 评论(0) 推荐(0) 编辑
摘要: //1. 使用大顶堆+小顶堆的容器. //2. 两个堆中的数据数目差不能超过1,这样可以使中位数只会出现在两个堆的交接处 //3. 大顶堆的所有数据都小于小顶堆,这样就满足了排序要求。平均数就在两个堆顶的数之中。 a. 为了保证两个堆中的数据数目差不能超过1,在Insert()方法中使用了count 阅读全文
posted @ 2018-01-15 11:13 qingtianBKY 阅读(215) 评论(0) 推荐(0) 编辑
摘要: // 使用堆排序实现 其时间复杂度为O(nlgn) private static void buildMaxHeap(int[] input, int end) { // 从非叶子节点开始进行 for (int i = (end - 1) / 2; i >= 0; i--) { // 当前节点 cu 阅读全文
posted @ 2018-01-14 13:26 qingtianBKY 阅读(102) 评论(0) 推荐(0) 编辑
摘要: public class 字符串全排列{ public static void allSortOfStr(char[] arr, int begin, int end) { if (begin == end) { // 只有一个字符进行全排序时,进行输出 for (int i = 0; i <= e 阅读全文
posted @ 2018-01-11 12:49 qingtianBKY 阅读(113) 评论(0) 推荐(0) 编辑
摘要: public class 二叉树中和为某为某一值的路径{ // 使用回溯算法 递归实现,分析好终止条件 public void findPath(TreeNode root, int expectedNum) { if (root == null) { return; } if (expectedN 阅读全文
posted @ 2018-01-10 14:09 qingtianBKY 阅读(148) 评论(0) 推荐(0) 编辑
摘要: public class 栈的压入弹出序列{ // 判断一个弹出序列是否为该压栈序列对应的一个弹出序列 public static boolean ispopAOrder(int[] pushA, int[] popA) { boolean res = false; // 辅助栈 Stack<Int 阅读全文
posted @ 2018-01-09 11:34 qingtianBKY 阅读(91) 评论(0) 推荐(0) 编辑