随笔分类 - algorithm
1
摘要:一个是O(n^2)一个是O(logn*n)两者都需要临时空间#include using namespace std;//time complex:n^nint longest_increase_sequence(int a[], int n){ if(n==1) return ...
阅读全文
摘要:有一个子串和一个集合,集合中的字符不重复,求子串中最短的包含集合的子串长度,如果不存在,返回0例:set: abcstring: axbyczabreturn: czab 4方法:用滑动窗口加上状态位来解决#include#include#include#include#include#includ...
阅读全文
摘要:http://mkdir1.github.io/最近在github上建立了一个blog, 这上面的就暂停更新了github上面还没有完成一个同步的效果功能,否则的话,也同步到这里该多好http://mkdir1.github.io
阅读全文
摘要:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of ...
阅读全文
摘要:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for a...
阅读全文
摘要:Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))...
阅读全文
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. ...
阅读全文
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definiti...
阅读全文
摘要:Given preorder and inorder traversal of a tree, construct the binary tree./** * Definition for binary tree * struct TreeNode { * int val; * Tr...
阅读全文
摘要:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n...
阅读全文
摘要:不用if.else.while等一切的条件判断这题真是涨知识了:1. #includetypedef int (*fun)(int);int f1(int i){ return 0;}int f2(int i){ fun f[2]={ f1,f2 }; return i+f[!!i...
阅读全文
摘要:/* * ===================================================================================== * * Filename: QuickSort.c * * Description: * * ...
阅读全文
摘要:#include #include using namespace std;const int maxn = 100;struct Node{ int key; Node *lchild, *rchild, *parent;};Node *p, node[maxn];int cnt;vo...
阅读全文
摘要:#include #include #include #include using namespace std;const int maxn = 100;bool g[maxn][maxn], visited[maxn];int n;queue q;void init(){ memset(g,...
阅读全文
摘要:1.判断单链表是否存在环2.找出环节点node* loopstart(node *head){ if(head==NULL) return NULL; node *fast = head, *slow = head; while(fast && fast->next){ ...
阅读全文
摘要:如4->4->6 + 2->4 = 4->7->0#include using namespace std;typedef struct node{ int data; node *next;}node;node* init(int a[], int n){ node *head=...
阅读全文
摘要:模板就是你的武器, 而真正的高手, 是不需要用任何武器的a b a a b c a c-1 0 0 1 1 2 0 1void getNext(const char* str,int next[]){ int i=0,j=-1; next[i]=j; asse...
阅读全文
摘要:算作字典树的入门吧, 挺实用的一个模板, 些许细节需要注意统计难题Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 15842Accepted Su...
阅读全文
摘要:题目描述: 输入一系列整数,建立二叉排序数,并进行前序,中序,后序遍历。输入: 输入第一行包括一个整数n(1struct Node{ int val; Node* left; Node* right; Node(int a):val(a),left(NULL),right...
阅读全文
摘要:题目描述:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。输入:输入可能包含多个测试样例,对于每个测试案例,输入的第一行为两个整数m和n(1#includeusing namespa...
阅读全文
1