随笔分类 - 算法
摘要:牛客网 剑指offer: https://www.nowcoder.com/ta/coding-interviews 1.二维数组中的查找 左到右递增,上到下递增; 解法:从左下遍历。大于则x--,小于则y++。 public class Solution { public boolean Find
阅读全文
摘要:0,1背包问题: 定义V(i,j):当前背包容量 j,前 i 个物品最佳组合对应的价值; 递推关系式: 1) j<w(i) V(i,j)=V(i-1,j) 2) j>=w(i) V(i,j)=max{ V(i-1,j),V(i-1,j-w(i))+v(i) } 参考:动态规划-01背包问题 网易20
阅读全文
摘要:堆排序可归纳为两个操作: 1)建堆:根据初始数组去构造初始堆(构建一个完全二叉树,保证所有的父结点都比它的孩子结点数值大)。 2)调整堆:每次交换第一个和最后一个元素,输出最后一个元素(最大值),然后把剩下元素重新调整为大根堆。 当输出完最后一个元素后,这个数组已经是按照从小到大的顺序排列了。调整堆
阅读全文
摘要:LeetCode: Tags-[Dynamic Programming]
阅读全文
摘要:1. Maximum Depth of Binary Tree: https://leetcode.com/problems/maximum-depth-of-binary-tree/ 最大深度: 解法1:<Recursive> 1 public class Solution { 2 public
阅读全文
摘要:二分法题型: (常规的三种主流写法:(<=)对应mid+1,mid-1; (<)对应mid+1,mid; (+1<)对应mid,mid;) (无证明推测:一般找具体tar的在循环内部返回的才会用<=(指的是返回全部情况 而不是个别情况);因为用<=循环后lo!=hi了,而是lo=hi+1; 所以不是
阅读全文
摘要:复杂度表: 冒泡排序、插入排序、选择排序 快排、归并排序、堆排序 希尔排序、桶排序、 (不稳定:选择排序、快排、堆排序) 463.Sort Integer 整数排序:http://www.lintcode.com/en/problem/sort-integers/ 1.冒泡排序 两两比较,每趟把最大
阅读全文
摘要:参考:十道面试题与十个海量数据处理方法总结 1.top K问题 分治/hash映射+hashmap统计+堆排序 (PS: 1.如果数据可以一次性放入内存则不需要分治;2.topK小用大根堆,topK大用小根堆;) 分治/hash映射:数据太大,内存受限;把大文件化成(取模映射)M个小文件; hash
阅读全文
摘要:Tags:Bit Manipulation
阅读全文
摘要:第1章: 9.Fizz Buzz :http://www.lintcode.com/zh-cn/problem/fizz-buzz/ 解法1:(% String.valueOf) (1.rst; 2.for(1,n),15,5,3,else; 3.return) 1 public class Sol
阅读全文
摘要:Tags:Tree 94. Binary Tree Inorder Traversal:https://leetcode.com/problems/binary-tree-inorder-traversal/ 中序遍历: (解法1:递归; 利用addAll 或者 helper(root,rst);
阅读全文
摘要:LeetCode: Tags-[Linked List] 2. Add Two Numbers: https://leetcode.com/problems/add-two-numbers/ 两个单链表代表倒序的数字, 求和: (Input: (2 -> 4 -> 3) + (5 -> 6 -> 4
阅读全文
摘要:Tags: Hash Table 3. Longest Substring Without Repeating Characters:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 没有重复字
阅读全文
摘要:Tags: Array Difficulty: Medium 11. Container With Most Water: https://leetcode.com/problems/container-with-most-water/ n条纵线,找出两条线使得容器最大:(题意:假设ai,aj Cm
阅读全文
摘要:Tags: Array Difficulty:Easy 1. Two Sum:https://leetcode.com/problems/two-sum/ 两数和,返回下标数组:(利用HashMap<Key,Value>遍历,其中用到containKey,get(key)--获取value; put
阅读全文
摘要:Difficulty--Naive 463.Sort Integer 整数排序:http://www.lintcode.com/en/problem/sort-integers/# 冒泡排序:(两两比较取出最大的放最后) (外循环-趟数0,n-1;内循环-有序区的比较次数n-i-1趟;判断a[j]
阅读全文

浙公网安备 33010602011771号