随笔分类 - 基础算法
LeetCode总结(搜索算法)
摘要:多少个孤岛 public class Solution { public int numIslands(char[][] grid) { int res = 0; if(grid.length==0) return 0; int m = grid.length; int n = grid[0].le
阅读全文
posted @ 2016-10-04 23:25
岳阳楼
剑指offer题目61-67
摘要:面试题61:把二叉树打印成多行 public class Solution { public ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) { ArrayList<ArrayList<Integer>> res = new ArrayLis
阅读全文
posted @ 2016-09-06 15:42
岳阳楼
剑指offer题目51-60
摘要:面试题51:数组中重复的数字 public class Solution { public boolean duplicate(int numbers[],int length,int [] duplication) { for(int i=0;i<length;i++){ if(numbers[i
阅读全文
posted @ 2016-09-06 15:39
岳阳楼
剑指offer题目41-50
摘要:面试题41:和为S的连续正整数序列 import java.util.ArrayList; public class Solution { public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) { ArrayLis
阅读全文
posted @ 2016-09-06 14:46
岳阳楼
剑指offer题目31-40
摘要:面试题31:连续字数组的最大和 public class Solution { public int FindGreatestSumOfSubArray(int[] array) { int len = array.length; if(len==0) return 0; int[] dp = ne
阅读全文
posted @ 2016-09-06 12:18
岳阳楼
剑指offer题目21-30
摘要:面试题21:包含min函数的栈 import java.util.Stack; public class Solution { private Stack<Integer> stack = new Stack<Integer>(); private Stack<Integer> minStack =
阅读全文
posted @ 2016-09-06 12:14
岳阳楼
剑指offer题目11-20
摘要:面试题11:数值的整数次方 public class Solution { public double Power(double base, int exponent) { if(exponent == 0) return 1.0; if(exponent == 1) return base; do
阅读全文
posted @ 2016-09-06 12:10
岳阳楼
剑指offer题目1-10
摘要:面试题3:二维数组中的查找 public class Solution { public boolean Find(int [][] array,int target) { boolean isFound = false; int m = array.length; int n = array[0]
阅读全文
posted @ 2016-09-06 12:09
岳阳楼
常用基础排序算法总结
摘要:插入排序 public static void sort(Object[] a, Comparator comparator) { int n = a.length; for (int i = 0; i < n; i++) { for (int j = i; j > 0 && less(a[j],
阅读全文
posted @ 2016-08-18 23:59
岳阳楼
LeetCode(六)
摘要:Min Stack class MinStack { // stack: store the stack numbers private Stack<Integer> stack = new Stack<Integer>(); // minStack: store the current min v
阅读全文
posted @ 2016-06-29 08:52
岳阳楼
LeetCode(五)
摘要:Minimum Depth of Binary Tree public class Solution { public int minDepth(TreeNode root) { if(root==null) return 0; int lh = minDepth(root.left); int r
阅读全文
posted @ 2016-06-28 23:25
岳阳楼
LeetCode(四)
摘要:Find Kth Largest Number public class Solution { public int findKthLargest(int[] nums, int k) { return findK(nums,nums.length - k,0,nums.length-1); } p
阅读全文
posted @ 2016-06-28 16:56
岳阳楼
LeetCode(三)
摘要:最长不重复子串 public class Solution { public int lengthOfLongestSubstring(String s) { if(s==null || s.length()==0){return 0;} int len = s.length(),maxLen=0,
阅读全文
posted @ 2016-06-28 16:38
岳阳楼
最短路径算法
摘要:Djkstra算法(单源最短路径) 算法的基本思想是:每次找到离源点(上面例子的源点就是 1 号顶点)最近的一个顶点,然后以该顶点为中心进行扩展,最终得到源点到其余所有点的最短路径。基本步骤如下: 将所有的顶点分为两部分:已知最短路程的顶点集合 P 和未知最短路径的顶点集合 Q。最开始,已知最短路径
阅读全文
posted @ 2016-06-15 09:59
岳阳楼
LeetCode(二)
摘要:实现Trie树 class TrieNode { public char val; public boolean isWord; public TrieNode[] children = new TrieNode[26]; public TrieNode() {} TrieNode(char c){
阅读全文
posted @ 2016-06-07 10:51
岳阳楼
LeetCode(一)
摘要:数据流的中位数 class MedianFinder { private Queue<Integer> maxHeap = new PriorityQueue(new Comparator<Integer>(){ @Override public int compare(Integer i1, In
阅读全文
posted @ 2016-06-01 11:36
岳阳楼
LeetCode340 Longest Substring with At Most K Distinct Characters
摘要:LeetCode340 Longest Substring with At Most K Distinct Characters
阅读全文
浙公网安备 33010602011771号