
算法
文章平均质量分 50
lifi_sysu
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
198. House Robber
标签(空格分隔): leetcode 原题 分析 代码 1. 原题你是一个大盗,要盗取一连串房子的金钱,但是房子的保安系统在你偷2家相邻的房子的时候才会触发。 2. 分析 收线如果nums是空向量,那么返回0.一定要首先排除简单的特殊情况 假设在nums[i]这个位置, 如果选择要偷取这一家的金钱,那么 (i - 1)th 家一定没有被偷,那么在这一家偷取到的金钱总数就是(i-2)th 家的金钱加上原创 2017-10-27 13:46:48 · 176 阅读 · 0 评论 -
565. Array Nesting
1. 原题A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].Sets S[K] for 0 <= K < N are defined as follows:S[K] = { A[K], A[A[K]],原创 2017-12-31 22:41:10 · 167 阅读 · 0 评论 -
72. Edit Distance
1. 原题Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2017-12-24 23:08:25 · 149 阅读 · 0 评论 -
671. Second Minimum Node In a Binary Tree
1. 原题Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node’原创 2017-11-24 20:59:54 · 158 阅读 · 0 评论 -
230. Kth Smallest Element in a BST
1. 原题Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST’s total element.2. 分析 题目要求找出宽度优先树中的第K小的树。 在没有这原创 2017-11-24 19:45:10 · 153 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
1. 原题2. 分析 从题目可以看出这是要将节点分层输出 宽度优先搜索要注意的几个点: 在递归式或者迭代式决定分层的,结束条件是什么。 这道题其实要求输出所有的节点,而且没有别的附加条件,只有按层输出,考虑到宽度优先中只有上一层完全搜索过之后,这一层才能搜索,也就是我们的数据结构中,到达新的一层时不能存储有上一层的。所以FCFS的队列合适:在搜索一个节点的时候, 将这个节点弹出并且将他的子节点加入队原创 2017-12-03 21:30:09 · 198 阅读 · 0 评论 -
495. Teemo Attacking
1. 原题In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning原创 2017-12-10 21:33:18 · 235 阅读 · 0 评论 -
152. Maximum Product Subarray
1. 原题Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest原创 2017-11-19 17:33:34 · 149 阅读 · 0 评论 -
368
标签(空格分隔): leetcode 原题 分析 代码 1. 原题Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If the原创 2017-11-03 19:00:14 · 288 阅读 · 0 评论 -
617. Merge Two Binary Trees
1. 原题2. 分析 可以看到题中要将两棵树求和, 没有的节点假设为0, 这样可以讲树的求和简化成每个节点的递归, 两棵树的大小也就可以视为一样,直到都检索完 每个节点求和之后,向左右继续递归 3. 代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *lef原创 2017-11-12 17:18:59 · 315 阅读 · 0 评论 -
718. Maximum Length of Repeated Subarray
标签(空格分隔): leetcode 原题 分析 代码 1.原题Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.2. 分析 采用动态规划的方法, 有2个数组, 以dp[i][j]表示以A[ i ] 和 B[ j ]结尾的最长的字符串 如果A[原创 2017-10-31 22:21:24 · 239 阅读 · 0 评论 -
算法概论8.15
最大独立集问题 要求任意图G=(V,E)G=(V ,E ) 中有大小为 d 的独立集, 令G1=G(V,E)G_1 = G(V,E) , G2=(V,∅)G_2 = (V ,∅) 也即是G2G_2各个顶点相互独立。于是G1G_1与G2G_2存在着大小为 d 的公共子图,当且仅当图G 存在着大小为 d 的独立集。原创 2017-12-31 23:48:10 · 183 阅读 · 0 评论