
ACM
文章平均质量分 64
夕阳下江堤上的男孩
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
字符串匹配问题——KMP算法
KMP算法用于解决字符串匹配问题。给定两个字符串S和T(假设strlen(S) > strlen(T)),判断S中是否包含T,且返回T在S中所在的起始位置。这里为简单起见,若S包含T,则只返回第一个T所在的位置。1、理论原创 2018-03-23 12:00:37 · 968 阅读 · 0 评论 -
回文最小分割数(palindrome-partitioning-ii)
class Solution {public: int minCut(string s) { //先求解小段的子序列 vector<vector<int>> dp(s.length(), vector<int>(s.length())); //存放最小切割数 vector<vector<bool>> p(s.lengt...原创 2018-08-06 11:46:53 · 481 阅读 · 0 评论 -
约瑟夫环
1、题目 n个数字(0,1,…,n-1)形成一个圆圈,从数字0开始, 每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字)。 当一个数字删除后,从被删除数字的下一个继续删除第m个数字。 求出在这个圆圈中剩下的最后一个数字。1、代码void Solution(int *arr, int length, int m){ if (lengt...原创 2018-07-21 14:02:28 · 307 阅读 · 0 评论 -
Number of Islands
1、题目Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may ...原创 2018-07-21 13:03:55 · 381 阅读 · 0 评论 -
二叉树非递归后序(后根)遍历
使用非递归方式对二叉树进行(后序)后根遍历原创 2018-07-15 20:17:49 · 1889 阅读 · 0 评论 -
max-points-on-a-line
在一个二维平面上,求最大的点个数,要求这些点在一条直线上。1、题目描述Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.2、思路 首先,两点确定一条直线; 假设某点A在最终的解中,那么只要分别计...原创 2018-07-19 13:58:56 · 432 阅读 · 0 评论 -
populating-next-right-pointers-in-each-node-ii
1、题目描述Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constan...原创 2018-07-19 10:38:02 · 292 阅读 · 0 评论 -
binary-tree-maximum-path-sum
1、题目描述Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.2、思路...原创 2018-07-19 10:18:14 · 293 阅读 · 0 评论 -
链表插入排序(insertion-sort-list)
对链表进行插入排序代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:原创 2018-04-28 22:11:02 · 488 阅读 · 0 评论 -
链表排序(sort-list)
链表排序1、要求: Sort a linked list in O(n log n) time using constant space complexity.2、代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne原创 2018-04-28 19:20:58 · 2321 阅读 · 0 评论 -
sum-root-to-leaf-numbers
1、题目描述:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total原创 2018-05-01 20:59:30 · 244 阅读 · 0 评论 -
归并排序
1、算法思路(分治策略)(1)划分:将待排序序列r1, r2, …, rn划分为两个长度相等的子序列r1, …, rn/2和rn/2+1, …, rn;(2)求解子问题:分别对这两个子序列进行排序,得到两个有序子序列;(3)合并:将这两个有序子序列合并成一个有序序列。2、代码实现void mergeArray(int data[], int first, int mid, int last, in...原创 2018-03-29 16:24:42 · 266 阅读 · 1 评论 -
堆排序
1、主要步骤:1)建堆2)筛选:自堆顶至叶子调整2、代码void heapAdjust(int data[], int s, int m) //默认是按照大顶堆调整{ int temp = data[s]; for (int j = 2 * s; j <= m; j *= 2) { if (j < m && data[j] < data[j + 1...原创 2018-03-29 15:14:09 · 275 阅读 · 0 评论 -
快速排序
1、算法思想选定一个记录作为支点(pivot),以支点为基准将整个序列划分为两个子序列r1 … ri-1和ri+1 … rn,前一个子序列中记录的值均小于或等于支点,后一个子序列中记录的值均大于或等于支点。这个过程chen原创 2018-03-28 17:54:08 · 353 阅读 · 0 评论 -
冒泡排序
1、原理冒泡排序在扫描过程中两两比较相邻记录,如果反序则交换,最终,最大记录就被“沉到”了序列的最后一个位置,第二遍扫描将第二大记录“沉到”了倒数第二个位置,重复上述操作,直到n-1 遍扫描后,整个序列就排好序了。2、算法实现2.1、基础版本void bubble_sort(int data[], int n) //从小到大排序{ for (int i = 0; i <= n - 2;...原创 2018-03-27 16:19:34 · 3018 阅读 · 0 评论 -
选择排序
1、原理选择排序的第i趟排序,从第i个记录开始扫描序列,在n-i+1(1≤i≤n-1)个记录中找到最小的记录,并和第i个记录交换作为有序序列的第i个记录。2、代码实现#includeusing namespace std;void select_sort(int data[], int n){ for (int i = 0; i <= n - 2; i++) //对原创 2018-03-27 15:31:09 · 357 阅读 · 0 评论 -
求最大子段和——分治法
1、分治策略(1)划分:按照平衡子问题的原则,将序列(a1, a2, …, an)划分成长度相同的两个子序列,则会出现以下三种情况:(2)求解子问题:对于划分阶段的情况①和②可递归求解,情况③需要计算s1+s2: (3)合并:比较在划分阶段的三种情况下的最大子段和,取三者之中的较大者为原问题的解。2、示意图3、代码实现i原创 2018-04-09 11:11:29 · 6849 阅读 · 1 评论 -
并查集详解(转)
转自 :https://blog.youkuaiyun.com/dellaserss/article/details/7724401原文地址:http://blog.youkuaiyun.com/niushuai666/article/details/6662911作者:飘过的小牛并查集是我暑假从高手那里学到的一招,觉得真是太精妙的设计了。以前我无法解决的一类问题竟然可以用如此简单高效的方法搞定。不分享出来真是对不起p转载 2018-04-01 21:24:27 · 217 阅读 · 0 评论 -
无向图拷贝(clone-graph)
思路:用深度优先(DFS)进行遍历 用map保存新旧值的映射关系代码:struct UndirectedGraphNode { int label; vector<UndirectedGraphNode *> neighbors; UndirectedGraphNode(int x) : label(x) {};};class Solution {...原创 2018-08-06 14:16:49 · 788 阅读 · 0 评论