自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(57)
  • 收藏
  • 关注

原创 STL hash_map

定义哈希函数和比较函数include include include using namespace std; //define the class struct ClassA { ClassA(int a):c_a(a){} int getvalue()const { return c_a;} size_t c_a; }; //1 defi

2015-09-03 10:54:17 322

原创 KMP模式匹配算法

先看看next数据值的求解方法 位序 1 2 3 4 5 6 7 8 9 模式串 a b a a b c a b c next值 0 1 1 2 2 3 1 2 3 next数组的求解方法是: 1.第一位的next值为0 2.第二位的next值为1 后面求解

2015-08-19 12:41:03 328

原创 回调函数

什么是回调函数? 简而言之,回调函数就是被调用者回头调用调用者的函数。 使用回调函数实际上就是在调用某个函数(通常是API函数)时,将自己的一个函数(这个函数为回调函数)的地址作为参数传递给那个被调用函数。而该被调用函数在需要的时候,利用传递的地址调用回调函数。 回调函数,就是由你自己写的,你需要调用另外一个函数,而这个函数的其中一个参数,就是你的这个回调函数名。这样,系统在必要的时候

2015-08-18 19:55:08 299

原创 Linux面试

1.简述Linux文件系统通过i节点把文件的逻辑结构和物理结构转换的工作过程。 答:Linux通过i节点表将文件的逻辑结构和物理结构进行转换。 i 节点是一个64字节长的表,表中包含了文件的相关信息,其中有文件的大小、文件所有者、文件的存取许可方式以及文件的类型等重要信息。在i节点表中最重要 的内容是磁盘地址表。在磁盘地址表中有13个块号,文件将以块号在磁盘地址表中出现的顺序依次读取相应的块。L

2015-08-09 16:27:19 478

原创 TCP传输层协议

TCP协议特点:面向连接、字节流、可靠传输 面向连接: 使用TCP协议的双方必须首先建立连接,并且双方都必须分配相应的内核资源。TCP的连接是全双工的,也就是说双方可以根据一个连接进行读写操作。 字节流: 1、当发送方多次写操作的时候,TCP发送模块会先把数据放在发送缓冲区中,当TCP发送模块真正发送的时候,这些在发送缓冲区中的数据才可能被封装成一个或多个报文段发出。所以,应用程序执行的写操

2015-08-07 17:20:22 437

原创 STL之priority_queue

#include <iostream> #include<functional>#include <queue> using namespace std; struct Node{ int x; Node( int a= 0):x(a) {} friend bool operator<(Node a,Node b ) { ret

2015-08-07 11:34:30 215

原创 STL中 map的用法

STL的排序问题,STL中默认是采用小于号来排序的,关键字是int型,它本身支持小于号运算,可以进行map的插入操作,但是一些其他的情况下,比如关键字是一个结构体,涉及到排序就会出现问题,因为它没有小于号操作,insert等函数在编译的时候过不去,下面给出两个方法解决这个问题 第一种:小于号重载,程序举例 #include<map>#include<iostream>#include<str

2015-08-06 17:02:15 266

原创 对给定字符串,取出它的子字符串,并把子字符串按照长度排序

#include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;bool myfunction (const string str1,const string str2) { return (str2.length() < str1.length());}void my

2015-08-04 23:28:25 445

原创 去除字符串中的重复子字符串

#include<iostream>#include<string>using namespace std;int delete_sub_str(char *input,char *sub_str,char *result){ int count=0; int len = strlen(sub_str); char *p = result; while(*in

2015-08-04 23:26:02 861

原创 取出整型数据中存在指定整数的数据,并按照升序排列返回

取出整型数据中存在指定整数的数据,并按照升序排列返回。 要求实现方法: public static int[] calcTimes(int[] num, int value); 【输入】 num:整型数组; value 指定的整数 【返回】 按照升序排列返回整型数组中包含指定整数的元素 示例 输入:num = {12345,654123,98764,12365

2015-08-04 23:24:26 1534 1

原创 socket、Tcp/IP通信

1.使用udp和tcp进程网络传输,为什么tcp能保证包是发送顺序,而 udp无法保证? 主机每次发送数据时,TCP就给每个数据包分配一个序列号并且在一个特定的时间内等待接收主机对分配的这个序列号进行确认,如果发送主机在一个特定时间内没有收到接收主机的确认,则发送主机会重传此数据包。接收主机利用序列号对接收的数据进行确认,以便检测对方发送的数据是否有丢失或者乱序等,接收主机一旦收到已经顺序

2015-07-27 22:44:13 961

原创 [leetcode]Word Ladder

#include<iostream>#include<string>#include<set>#include<unordered_set>#include<unordered_map>#include<map>#include<deque>using namespace std;class Solution{public: int wordladder(string s

2015-07-25 15:03:23 203

原创 [leetcode]Search for a Range

#include<iostream>#include<vector>using namespace std;class Solution1{public: vector<int> findindex(vector<int>a,int target) { vector<int>res; int first=0,last=a.size()-1;

2015-07-24 21:56:12 195

原创 [leetcode]Search Insert Position

#include<iostream>#include<vector>using namespace std;class Solution{public: int findindex(vector<int>a,int target) { if(a.empty()) return 0; int first=0,last=a

2015-07-24 17:24:23 173

原创 [leetcode]Search a 2D Matrix

#include<iostream>#include<vector>using namespace std;class Solution{public: bool find(vector<vector<int>>a,int target) { int l=0; int r=a.size()*a.back().size()-1;

2015-07-24 17:07:14 172

原创 [leetcode]First Missing Positive

#include<iostream>using namespace std;void findfirstpositive(int a[],int length){ for(int i=0;i<length;i++) { if(a[i]>0&&a[i]<=length&&i!=a[i]-1) { swap(a[i],a[a[i

2015-07-20 17:13:51 194

原创 [leetcode] Insertion Sort List

#include<iostream>using namespace std;struct ListNode{ int value; ListNode* next; ListNode(int value):value(value),next(NULL){};};ListNode* Insertsort(ListNode* head){ if(!head)

2015-07-20 15:47:37 214

原创 排序

#include<iostream>using namespace std;void Insertsort(int a[],int length){ /*int i,j,temp; for(i=0;i<length-1;i++) { j=i+1; if(a[j]<a[i]) { temp=a[j];

2015-07-18 11:48:01 187

原创 [leetcode] Convert Sorted List to Binary Search Tree

#include<iostream>#include<vector>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){};};struct ListN

2015-07-17 16:32:49 220

原创 [leetcode]Convert Sorted Array to Binary Search Tree

#include<iostream>#include<vector>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){};};class Soluti

2015-07-17 14:51:07 200

原创 Validate Binary Search Tree

#include<iostream>#include<vector>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){};};class Soluti

2015-07-17 11:15:20 212

原创 [leetcode]Unique Binary Search Trees II

#include<iostream>#include<vector>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){};};class Soluti

2015-07-16 22:40:57 229

原创 面试题目积累

19.C++多态的实现原理 对于虚函数调用来说,每一个对象内部都有一个虚表指针,该虚表指针被初始化为本类的虚表。所以在程序中,不管你的对象类型如何转换,但该对象内部的虚表指针是固定的,所以呢,才能实现动态的对象函数调用,这就是C++多态性实现的原理。

2015-07-16 22:36:18 588

原创 【leetcode】Construct Binary Tree from Preorder and Inorder Traversal

#include<iostream>#include<vector>#include<map>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){};};

2015-07-16 17:28:07 184

原创 【leetcode】Populating Next Right Pointers in Each Node II

#include<iostream>#include<vector>#include<deque>#include<stack>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL

2015-07-14 15:21:10 137

原创 【leetcode】Flatten Binary Tree to Linked List

前序遍历二叉树,并进行扁平化处理#include<iostream>#include<vector>#include<deque>#include<stack>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):va

2015-07-14 11:01:02 154

原创 【leetcode】Same Tree和Balanced Binary Tree

#include<iostream>#include<vector>#include<deque>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){};

2015-07-13 23:32:08 137

原创 Recover Binary Search Tree

#include<iostream>#include<vector>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){};};class Soluti

2015-07-13 21:23:16 156

原创 [leetcode] Binary Tree Zigzag Level Order Traversal

#include<iostream>#include<list>#include<queue>#include<vector>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int value):val(value),left(NU

2015-07-13 16:11:31 140

原创 [leetcode]Binary Tree Level Order Traversal II

#include<iostream>#include<list>#include<queue>#include<vector>using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int value):val(value),left(NU

2015-07-13 16:07:51 171

原创 Morris遍历二叉树

#include<iostream>#include<list>using namespace std;struct TreeNode{ int value; TreeNode* left; TreeNode* right; TreeNode(int value):value(value),left(NULL),right(NULL){};};class So

2015-07-13 10:56:01 209

原创 【leetcode】Evaluate Reverse Polish Notation

#include<iostream>#include<stack>#include<string>#include<vector>using namespace std;class Solution{public: double fun(vector<string> a) { stack<string>result; for(int i=0

2015-07-11 15:55:16 156

原创 【leetcode】Largest Rectangle in Histogram

#include<iostream>#include<vector>using namespace std;class Solution{public: int fun(vector<int> a) { int i; int maxlength=0; for( i=0;i<a.size();i++) {

2015-07-11 14:01:31 193

原创 【leetcode】Longest Valid Parentheses

#include<iostream>#include<stack>#include<vector>#include<string>#include<algorithm>using namespace std;struct Node{ int key; char c; Node(int key,char c):key(key),c(c){};};class So

2015-07-11 10:56:46 136

原创 【leetcode】 Anagrams

代码1:#include<iostream>#include<string>#include<vector>#include<algorithm>#include<map>using namespace std;class Solution{public: string fun(vector<string> str) { string a="";

2015-07-08 15:58:54 205

原创 Wildcard Matching

迭代:#include<iostream>using namespace std;class Solution{public: bool isMatch(const char *s, const char *p) { int i=0,j=0; bool str=false; for(;s[i]!='\0

2015-07-07 20:31:52 227

原创 Longest Palindromic Substring

暴力解法:#include<iostream>#include<string>using namespace std;string expand(string a,int l,int r){ while(l>=0&&r<a.size()) { if(a[l]==a[r]) { l--; r++;

2015-07-07 14:58:05 218

原创 LRU Cache的C++实现

方法一:双链表+哈希表map#include<iostream>#include<map>using namespace std;struct Node{ int key; int value; Node* pre; Node* next; Node(int key=-1,int value=-1):key(key),value(value),pre(

2015-07-05 16:02:44 337

原创 【leetcode】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, G

2015-07-03 10:15:33 191

原创 Single Number II

leetcode Single Number II 描述 Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could

2015-07-01 15:11:32 205

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除