算法和数据结构
文章平均质量分 63
ZhatianYuan
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
二叉树
struct BinaryTreeNode { int val; BinaryTreeNode* left; BinaryTreeNode* right; }; 一、判断二叉树B是不是A的子树 bool DoseTree1HasTree2(BinaryTreeNode* pRoot1,BinaryTreeNode* pRoot2) { if(pRoot2==NULL) return原创 2017-03-30 16:38:07 · 234 阅读 · 0 评论 -
10. Regular Expression Matching
方法一、p[j+1]=='*',此时从s[i]开始的子串,假设是s[i],s[i+1].....s[i+k]都等于p[j],则意味着这些都可能是合适的匹配,这就得递归剩下的(i,j+2),(i+1,j+2).......(i+k,j+2) 实现代码:bool isMatch(string s, string p) { return check(s,p,0,0); }原创 2017-06-06 10:37:55 · 244 阅读 · 0 评论 -
44. Wildcard Matching
'?' Matches any single character. '*' Matches any sequence of characters (including the empty sequence). The matching should cover the entire input string (not partial). The function prototype shoul原创 2017-06-06 14:02:38 · 199 阅读 · 0 评论 -
31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible原创 2017-06-08 21:09:23 · 233 阅读 · 0 评论 -
SkipList -----跳表
今天学习了一个非常高效的数据结构,那就是跳表。其查找效率比红黑树要更高。整个的实现见下面://参考:Skip lists: a probabilistic alternative to balanced trees #ifndef _SKIPLIST_H_ #define _SKIPLIST_H_ #include #include #include #include #define原创 2017-06-30 21:10:20 · 334 阅读 · 0 评论 -
37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. 这道题是一个回溯法来解决的问题,依次试探每一种可能的情况,当满足这一情况时再向后递归直至整个问题解决。真正理解了回溯法的强大 啊,感谢啊 。 void原创 2017-06-11 21:10:29 · 225 阅读 · 0 评论 -
60. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123""132""213""231""3原创 2017-06-23 21:32:21 · 302 阅读 · 0 评论 -
69. Sqrt(x)
Implement int sqrt(int x). Compute and return the square root of x. 好精妙的方法啊 int mySqrt(int x) { long r = x; while (r*r > x) r = (r + x/r) / 2; return r;原创 2017-06-27 15:20:37 · 263 阅读 · 0 评论 -
76. Minimum Window Substring 10-line template that can solve most 'substring' problems
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BAN原创 2017-06-28 10:23:05 · 314 阅读 · 0 评论 -
数组里面的数字的组合为某个和以及二叉树的某个路径的和为某值的全部路径
这种类型的题目有两种, 第一种情况下可以对里面的数字重复使用, vector> vec; vector> combinationSum(vector& candidates, int target) { sort(candidates.begin(),candidates.end()); vector local; check(candi原创 2017-05-08 20:50:31 · 271 阅读 · 0 评论 -
字符串的最长回文子序列以及最长子串
//最长子序列 int longestPalindromeSubseq(string s) { int size = s.size(); vector> dp(size,vector(size,0)); for(int i=0;i<size;i++) dp[i][i]=1; for(int len=1;len<原创 2017-05-08 17:01:50 · 316 阅读 · 0 评论 -
二叉树的三种非递归遍历
struct TreeNode { int val; TreeNode *left; TreeNode *right; }; void PreOrder(TreeNode *root) { if(root==NULL) return; stack stk; TreeNode *p = root; while(p!=NULL||stk.empty()) { while(p!=原创 2017-04-27 18:30:00 · 216 阅读 · 0 评论 -
顺时针打印矩阵的元素啊
void PrintMatrixIncircle(int** numbers,int columns,int rows,int start) { int endX = columns-1-start; int endY = rows-1-start; for(int i = start;i<=endX;i++) { int number = numbers[start][i];原创 2017-03-30 18:08:51 · 356 阅读 · 0 评论 -
打印1到最大的n位数
void PrintNum(char* number) { bool Beginning0=true; for(unsigned int i = 0;i<strlen(number);i++) { if(Beginning0&&number[i]!='0') Beginning0 = false; if(!Beginning0) printf("%c",number[i]原创 2017-03-30 15:04:15 · 189 阅读 · 0 评论 -
数组中只出现一次的数字
//一个数组里面的所有的数字出现两次,只有一个数只出现一次,找出这个数 void FindUniqueNum(vector p,int num) { num = 0; for(int i = 0;i<p.size();i++) num^=p[i]; } //一个数组里面的其余的数出现两次,有两个不同的数出现一次,找出这两个数 void FindTwoUniqueNum(vector p,i原创 2017-04-28 13:26:51 · 211 阅读 · 0 评论 -
链表删除节点
struct ListNode { int val; ListNode *next; ListNode(int x):val(x),next(NULL){} }; //从一个链表中删除重复的节点,保留一个该节点 ListNode* deleteDuplicates(ListNode* head) { if(head==NULL) return head; ListNode *pre原创 2017-04-28 15:37:54 · 342 阅读 · 0 评论 -
有序链表的合并
ListNode* Merge(ListNode* p1,ListNode* p2) { if(p1==NULL) return p2; if(p2==NULL) return p1; if(p1->valval) { p1->next = Merge(p1->next,p2); return p1; } else { p2->next原创 2017-04-28 19:59:52 · 238 阅读 · 0 评论 -
总结排序算法
void QSort(int *num,int low,int high) { int pivot; if(low<high) { pivot=Partition(num,low,high); QSort(num,low,pivot-1); QSort(num,pivot+1,high); } } int Partition(int *num,int low,int原创 2017-03-08 16:25:26 · 214 阅读 · 0 评论 -
硬币组合问题
//硬币的找零问题,给定一个数值,求使得最少的硬币数组合成所要的数值 int CoinChange(vector coins,int len,int sum) { vector dp(sum+1,sum+1); dp[0]=0;//设定为0 for(int i=1;i<=sum;i++) { for(int j=0;j<len;j++) { if(coins[j]<=i)原创 2017-05-06 16:55:33 · 365 阅读 · 0 评论 -
10. Regular Expression Matching
'.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(c原创 2017-08-26 15:33:15 · 281 阅读 · 0 评论
分享