algorithm
文章平均质量分 71
喵喵旺
这个作者很懒,什么都没留下…
展开
-
[小总结]常见order-of growth
听coursera的算法课截屏的一张图,常见order-of-growth的总结原创 2017-02-08 01:13:27 · 2143 阅读 · 0 评论 -
[Algorithm]九章九之一:Matrix DP
109. Triangle:点击打开链接方法一:自底向上例如:从6开始,依赖于4和1中小者,再加上本身注意:这种三角形第n行的长度是n+1,一共有n-1行,第0行的长度为1,Time:O(n^2),而如果用DFS则需O(2^n),因此可知DP优化了很多[ [2], [3,4], [6,5,7], [4,1,8,3]][ [2],...原创 2017-06-27 23:46:01 · 352 阅读 · 0 评论 -
[Algorithm]九章四:BSF
69. Binary Tree Level Order Traversal:点击打开链接Time: O(n)/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(...原创 2017-05-11 08:53:47 · 632 阅读 · 0 评论 -
[LeetCode] Merge问题
88.Merge Sorted Array:点击打开链接public class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { //从后往前放比较过程中的较大值 int i=m-1,j=n-1,index=m+n-1; while(i>=0 && j>=0原创 2017-06-18 03:53:01 · 249 阅读 · 0 评论 -
[Algorithm] 九章二:Binary Search
457.经典二分叉中分问题:点击打开链接注意:二分查找模板 牢记二分查找精髓,不断缩小范围,然后手动找出结果(并不是在缩小范围的时候就一定能找到结果) public class Solution { /** * @param nums: An integer array sorted in ascending order *...原创 2017-05-02 05:22:57 · 412 阅读 · 0 评论 -
[Algorithm]九章五.DFS
做DFS的题,想象构造树非常关键,把树构造的过程梳理清楚了,自然递归的步骤也就出来了。17. Subsets: 点击打开链接思路:对于[1,2,3] [ ] [1] 这边的1是在[ ]的基础上添加的 [1,2] [1,3] 所以倒回来到[1,3]的时候也应该知道是在[1]的基础上添加的[1,2,3]因为这层是在[...原创 2017-05-13 09:58:19 · 522 阅读 · 0 评论 -
[Algorithm]九章七:Two Pointer
604. Window Sum:点击打开链接例如:[1,2,7,8,5], k=3sum[0]=nums[0]+nums[1]+nums[2]=10sum[1]=sum[0]-nums[0]+nums[0+3]=17,也就是说sum[1]=10-1+8sum[2]=sum[1]-nums[1]+nums[1+3]=20,也就是说sum[2]=17-2+5窗口向后滑动,要减去(滑...原创 2017-06-12 07:27:50 · 1692 阅读 · 0 评论 -
[Algorithm]九章三:Binary Tree & Divide Conquer
97.Maximam Depth of Binary Tree: 点击打开链接/* Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * ...原创 2017-05-06 05:04:02 · 430 阅读 · 0 评论 -
[Algorithm]九章六之二: Array
6. Merge Two Sorted Arrays :点击打开链接class Solution { /** * @param A and B: sorted integer array A and B. * @return: A new sorted integer array */ public int[] mergeSortedArray(i原创 2017-06-12 07:24:15 · 493 阅读 · 0 评论 -
[Algorithm] Combination问题
Combination IIIFind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.原创 2017-07-14 00:49:03 · 313 阅读 · 0 评论 -
[Algorithm]九章八:Data Structure
128. Hash Function:点击打开链接思路:所有的sum算完最后取模,和一边算一边取模,最后的结果是一样的 但是边算边取可以防止超出范围class Solution { /** * @param key: A String you should hash * @param HASH_SIZE: An integer ...原创 2017-06-12 07:29:12 · 592 阅读 · 0 评论 -
[Algorithm]Quick Select问题
5.Kth Largest Element:点击打开链接例如:[9,3,2,4,8],k=3,Output:4,也就是第3rd大的是4,[2,3,4,8,9]思路:1. 用当前数组中间的数作为pivot标杆,用O(n)的时间使得大于pivot的数都在左边部分,小于pivot的数都在右边部分 2. 然后就要进行一轮判断,如果判断出k会在左边部分,右边部分就不用再递归了原创 2017-06-22 02:18:19 · 596 阅读 · 0 评论 -
[Algorithm] Palindrome 问题
9. Palindrome Number:点击打开链接public class Solution { public boolean isPalindrome(int x) { //不同解题思维 int temp = 0; int startX=x; while(x>0){ temp = temp*10 + (x %原创 2017-06-12 07:37:06 · 400 阅读 · 0 评论 -
[Algorithm]九章九之二:Sequence
116. Jump Game:点击打开链接思路:贪心例如:[2,3,1,1,4]--每个位置可以跳的步数 0,1,2,3,4 --每个位置index分析:初始化reach=nums[0]可以跳2步,从1开始遍历i,遍历到的位置+该位置可以走的步数>=当前的reach 更新reach值就是可以到达的位置 直到reach大于...原创 2017-06-29 10:34:44 · 296 阅读 · 0 评论 -
[Algorithm] 九章一:算法面试与代码风格
面试原创 2017-03-05 06:22:48 · 561 阅读 · 0 评论 -
[Algorithm]九章六之一:LinkedList
35.Reverse Linked List :点击打开链接/** * Definition for ListNode. * public class ListNode { * int val; * ListNode next; * ListNode(int val) { * this.val = val; * ...原创 2017-06-10 01:24:11 · 434 阅读 · 0 评论 -
[Algorithm] Rotate 问题
Rotate StringGiven a string and an offset, rotate string by offset. (rotate from left to right)Have you met this question in a real interview? YesExampleGiven "abcdef原创 2017-07-25 02:52:12 · 281 阅读 · 0 评论 -
[Algorithm]九章必背程序--stack:Non Recursion
66. Binary Tree Preorder Traversal :点击打开链接/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { *原创 2017-05-13 10:20:05 · 372 阅读 · 0 评论 -
[Algorithm] BST问题
BST性质:左边都比root小,右边都比root大BST的中序遍历得到的节点访问顺序是从小到大的顺序98. Valid Binary Search Tree:点击打开链接方法一思路:先中序遍历BST拿到结果list,遍历list里元素,看当前的元素值是不是小于下一个元素值,只要有当前元素值大于等于下一个元素值的,就返回false/** * Definition of Tree原创 2017-07-12 01:13:02 · 513 阅读 · 0 评论 -
Duplicate问题
219.Contains Duplicate IIGiven an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and theabsolutedifference be...原创 2019-07-03 03:11:53 · 1294 阅读 · 0 评论