- 博客(40)
- 收藏
- 关注
转载 寻找包含给定字符集合的最小子串
#include #include using namespace std;string min_str(string str1,string str2){ if(str1.size() == str2.size() ) { return min(str1,str2); } return str1.size() > str2.size()
2014-09-17 17:35:46
757
转载 TCP三次握手及四次挥手
http://www.cnblogs.com/hnrainll/archive/2011/10/14/2212415.html
2014-09-15 18:05:17
418
原创 【面试准备】八皇后问题
#include using namespace std;#define Slove_num 8int seat[Slove_num];bool ok(int n);int count = 0;void queen(int n){ if(n == Slove_num){ for(int i = 0;i < n; ++i){ cout<<"("<<i<<","<<seat
2014-09-04 16:12:15
466
原创 找出数组中只出现一次的2个数
1. 首先数组中所有元素依次异或,因为相同的元素异或得到0,所以最终的答案就等于那2个唯一的元素a^b的值。2. 因为a,b不同,所以异或得到的答案肯定是不等于0的,那么我们就找到a^b的二进制表示中第一个为1的位,假如是第k位。而a,b两个数在第k位上是不同的,一个为0,一个为13. 接下来我们将第k位是1的分成一组,第k位是0的分成一组,如果2个元素相同,那么他们第k位肯定是一
2014-09-03 16:01:02
406
原创 【面试准备】letcode-Copy List with Random Pointer
/** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label; * RandomListNode *next, *random; * RandomListNode(int x) : label(x), next(NULL),
2014-09-03 15:34:47
425
原创 【面试准备】letcode-Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"
2014-09-03 10:19:24
606
原创 【面试准备】letcode-Tow Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe
2014-09-03 09:13:02
553
原创 【面试准备】letcode-Linked List Cycle |
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bo
2014-09-02 21:47:34
419
原创 【面试准备】letcode-Linked List Cycle ||
快慢指针遍历/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: List
2014-09-02 21:40:27
416
原创 【面试准备】letcode-Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to
2014-09-02 20:39:02
476
原创 【面试准备】letcode-Binary Tree Preorder Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti
2014-09-02 19:41:34
424
原创 【面试准备】letcode—LRU
#include #include #include using namespace std;struct CacheNode{ int key; int value; CacheNode(int x,int y):key(x),value(y){}};class LRUCache{public: LRUCache(int capacity){ size = capa
2014-09-02 18:36:57
437
转载 【面试准备】list
STL中list的使用:STL中的list就是一双向链表,可高效地进行插入删除元素。现总结一下它的操作。文中所用到两个list对象c1,c2分别有元素c1(10,20,30) c2(40,50,60)。还有一个list::iterator citer用来指向c1或c2元素。list对象的声明构造():A. listc0;
2014-09-02 18:03:12
615
原创 【面试准备】letcode-Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
2014-09-02 16:41:15
544
原创 【面试准备】letcode—sort list
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int
2014-09-02 16:16:57
420
原创 【面试准备】letcode—Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.#include #include #include using namespace std;struct Point{ int x; int y; Point(): x(0),
2014-09-02 14:50:47
403
转载 【面试准备】map
Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map最基本的构造函数; mapmapstring; mapmapint; mapmapstring; mapmapchar; mapmapchar; mapmapint
2014-09-02 14:24:04
372
原创 【面试准备】letcode-Evaluate Reverse Polish Notation
Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/", "+"] -> (4 + (13
2014-09-02 11:00:58
417
原创 【面试准备】字符串反序
#include #include #include using namespace std;void reverseWords(string &s) { string a[s.length()]; int j = 0; int aa = 0; int i = 0; char *w = (char*) ma
2014-09-02 09:37:34
459
原创 【面试准备】求字符串中最长的重复子串
#include #include using namespace std;void substr(char *a) //统计数组a中重复出现的最长的子序列 { int n; for (n = 0; a[n] != '\0'; ++n) ; int count = 1; for (int len = n - 1; len > 0; --len) //len:子串的长度
2014-09-02 08:30:29
484
原创 【面试准备】堆排
#include using namespace std;void AdjastHeapSort(int a[],int i,int n){//调整节点i,数组共有n个节点 if(n == 1||i >(n-2)/2){ return ; } int iLeft = 2*i+1;//i从0开始 int iRight = 2*i+2; if(iRight<=n-1){ if
2014-09-01 22:04:49
485
原创 【面试准备】快排
#include using namespace std;void Quicksort(int e[],int first,int end){ int i = first, j = end; int temp = e[i]; while(i<j){ while(i<j && temp<=e[j]){ j--; } e[i] = e[j]; while(i<j &
2014-09-01 19:57:08
428
原创 【面试准备】最长公共子序列
#include #include using namespace std;#define MAXLEN 100void LCSLength(char* x, char *y, int m, int n, int c[][MAXLEN], int b[][MAXLEN]) {//c[][]记录x[i]与y[i]的LCS长度;b[][]记录c[i][j]是通过哪一个子问题的值求得的以决
2014-09-01 19:06:59
371
原创 面试准备——最长公共子串
#include #include using namespace std;string Get_length(string& s,string& t){ int p = s.length(); int q = t.length(); string **num = new string *[p]; for(int i = 0 ; i < p ; ++i)
2014-09-01 09:38:05
390
原创 【面试准备】数据结构-Huffman树
#include using namespace std;//Hanfuman树节点类templateclass HuffmanNode {private: HuffmanNode *left, *right; T data; int weight;public: HuffmanNode() { ; } HuffmanNode(HuffmanNode* L, Huff
2014-08-05 14:53:15
527
原创 【面试准备】C语言printf输出格式
%a 浮点数、十六进制数字和p-记数法(C99)%A 浮点数、十六进制数字和p-记法(C99)%c 一个字符 %d 有符号十进制整数 %e 浮点数、e-记数法%E 浮点数、E-记数法%f 浮点数、十进制记数法 %g 根据数值不同自动选择%f或%e.%G 根据数值不同自动选择%f或%e.%i
2014-08-02 19:29:21
437
转载 【面试准备】C文件操作函数
C语言文件操作函数大全clearerr(清除文件流的错误旗标)相关函数 feof表头文件 #include定义函数 void clearerr(FILE * stream);函数说明 clearerr()清除参数stream指定的文件流所使用的错误旗标。返回值 fclose(关闭文件)相关函数 close,fflush,fopen,setbuf表头文件 #i
2014-08-02 19:27:04
446
原创 【面试准备】数据结构-二叉树
#include using namespace std;templateclass BinTreeNode{private: BinTreeNode *left,*right; T data;public: BinTreeNode(BinTreeNode *lptr,BinTreeNode *rptr,T& item){ left = lptr; right = r
2014-08-02 19:25:36
479
原创 【面试准备】数据结构-堆栈
#include using namespace std;templateclass AStack{private: int size; T* stackArray; int top;public: AStack(int MaxStackSize){ size = MaxStackSize; stackArray = new T[MaxStackSize]; top
2014-08-02 19:23:56
453
原创 【面试准备】数据结构-队列
#include using namespace std;template struct SLNode{ T data; SLNode* next; SLNode(SLNode* nextnode = NULL){ next = nextnode; } SLNode(const T& item,SLNode* nextnode = NULL){ data = item
2014-08-02 19:22:30
398
原创 [面试准备】数据结构--链表
#include using namespace std;//链表节点定义template struct SLNode{ T data; SLNode* next; SLNode(SLNode* nextnode = NULL){ next = nextnode; } SLNode(const T& item,SLNode* nextnode = NULL){ da
2014-08-02 19:20:40
572
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人