![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
文章平均质量分 72
犹影随行
这个作者很懒,什么都没留下…
展开
-
LeetCode:Maximum Depth of Binary Tree
转载自 http://www.cnblogs.com/bakari/p/4126693.html要求:求二叉树的深度(二叉树的深度为最远叶子节点到根节点的距离,即根节点到最远叶子节点的距离)Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along th转载 2015-02-07 12:47:37 · 262 阅读 · 0 评论 -
算法导论:分治策略__最大子数组问题
可以参考http://segmentfault.com/blog/binta/1190000000733277//参考书上源代码,但是对于分治法求解,返回子数组范围在一些情况下有一些问题。// 求最大子数组 暴力法与分治法#include #include #include using namespace std;// 暴力求解法int maxsubset(int* a转载 2015-02-09 18:17:36 · 300 阅读 · 0 评论 -
LeetCode: Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha转载 2015-02-09 18:57:32 · 255 阅读 · 0 评论 -
Dijkstra算法步骤及代码
转载自:http://www.cnblogs.com/dolphin0520/archive/2011/08/26/2155202.html动画演示:http://www.ntnoi.cn/FLASH/arithmetic/2010-05-17/23.html http://baike.baidu.com/view/1712262.htm 单源最短路径问题,即在图中求出给定顶转载 2015-02-23 00:39:07 · 11036 阅读 · 0 评论 -
二叉树的深度优先与广度优先遍历
来自:http://www.blogjava.net/fancydeepin/archive/2013/02/03/395073.html(第一:这里注意程序中对树的深度优先遍历与对图的深度优先遍历的区别;第二:注意使用深度优先与广度优先方法可以使用迭代的方法进行实现,也可以使用堆栈和队列对算法进行辅助。)深度优先搜索算法(Depth First Search),是搜索算法转载 2015-02-22 20:27:42 · 495 阅读 · 0 评论 -
算法导论:快速排序代码
#include using namespace std;void exchange(int& a, int& b){ int temp; temp = a; a = b; b = temp;}int part(int* a,int p,int r){ int x = a[r]; int i = p-1; for(int j翻译 2015-02-12 08:24:27 · 344 阅读 · 0 评论 -
LeetCode:Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element转载 2015-02-12 17:04:46 · 422 阅读 · 0 评论 -
LeetCode:Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.主要参考一下博客:http://blog.csdn.net/kenden23/article/details/13274385http://blog.csdn.net/a836转载 2015-02-12 20:37:19 · 300 阅读 · 0 评论 -
算法导论:动态规划
top-down实现#include #include #include using namespace std;int cutRod(int* p, int n){ if(n==0) return 0; int q = INT_MIN; for(int i=1;i<=n;i++) { q=max(q,p[i-1]+c翻译 2015-02-14 12:43:55 · 549 阅读 · 0 评论