自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

转载 数据流中的中位数

template<typename T> class DynamicArray{public: void Insert(T num) { if(((min.size() + max.size()) & 1) == 0) { if(max.size() > 0 && num <...

2018-03-31 08:36:49 125

转载 NoSQL数据库的伸缩性设计

转载:http://www.360doc.com/content/17/1209/21/40769523_711635612.shtml

2018-03-24 07:53:45 445

转载 单例模式

#include <iostream>using namespace std;class Singleton{public: static Singleton *GetInstance() { if (m_Instance == NULL ) { Lock(); // C++没有直接的Lock操作,请使用...

2018-03-22 13:52:46 122

转载 外观模式

外观模式是说为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。通俗点说就是通过定义一个一致的接口,用以屏蔽内部子系统的细节,使得调用端只需跟这个接口发生调用,而无需关心这个子系统的内部细节。外观模式中的角色:1.外观类(Facade)为调用端提供统一的调用接口。外观类知道哪些子系统负责处理请求,从而将调用端的请求代理给适当的子系统对象。2.调用者...

2018-03-22 11:12:15 81

转载 桥接模式

桥接模式(Bridge)是一种结构型设计模式。Bridge模式基于类的最小设计原则,通过使用封装、聚合及继承等行为让不同的类承担不同的职责。它的主要特点是把抽象(Abstraction)与行为实现(Implementation)分离开来,从而可以保持各部分的独立性以及应对他们的功能扩展。桥接模式的角色和职责:1.Client 调用端这是Bridge模式的调用者。2.抽象类(Abstraction)...

2018-03-22 10:54:19 111

转载 内存文件系统设计

Design an in-memory file system to simulate the following functions:ls: Given a path in string format. If it is a file path, return a list that only contains this file's name. If it is a directory pat...

2018-03-22 08:36:28 881

转载 LFU Cache

Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get andput.get(key) - Get the value (will always be positive) of the key if the...

2018-03-21 08:54:17 164

转载 hash操作

#include <iostream>#include <ctime>using namespace std;const int NIL= -1;//为了简便,NIL设为-1const int m = 20; //hash表大小void InitHash(int T[m]){ for (int i=0 ; i<m ; i++) T[i] = NI...

2018-03-21 08:30:09 483

转载 检测ip地址字符串是否正确

bool isValidIP(char* str){ if (NULL==str) { return false; } bool preIsNum=false; int numOfPoint=0; int numOfNum=0; char *p=str; while ('\0'!=*p&&numOfPoint<=3&&numOfNum&lt...

2018-03-19 20:07:52 382

转载 二叉搜索树与双向链表

BinaryTreeNode* Convert(BinaryTreeNode* pRootOfTree){ BinaryTreeNode *pLastNodeInList = nullptr; ConvertNode(pRootOfTree, &pLastNodeInList); // pLastNodeInList指向双向链表的尾结点, // 我们需要...

2018-03-17 10:34:05 130

转载 之字形打印二叉树

void Print(BinaryTreeNode* pRoot){ if(pRoot == nullptr) return; std::stack<BinaryTreeNode*> levels[2]; int current = 0; int next = 1; levels[current].push(pRoot);...

2018-03-17 10:28:58 200

转载 分行从上到下打印二叉树

void Print(BinaryTreeNode* pRoot){ if(pRoot == nullptr) return; std::queue<BinaryTreeNode*> nodes; nodes.push(pRoot); int nextLevel = 0; int toBePrinted = 1; wh...

2018-03-17 10:20:04 379

转载 栈的压入、弹出序列

题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1、2、3、4、5是某栈的压栈序列,序列4、5、3、2、1是该压栈序列对应的一个弹出序列,但4、3、5、1、2就不可能是该压栈序列的弹出序列。bool IsPopOrder(const int* pPush, const int* pPop, int nLength){...

2018-03-17 10:17:03 119

转载 表示数值的字符串

题目:请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串“+100”、“5e2”、“-123”、“3.1416”及“-1E-16”都表示数值,但“12e”、“1a3.14”、“1.2.3”、“+-5”及“12e+5.4”都不是// 数字的格式可以用A[.[B]][e|EC]或者.B[e|EC]表示,其中A和C都是// 整数(可以有正负号,也可以没有),而B是一个无符号整数...

2018-03-17 10:01:36 207

转载 对称的二叉树

bool isSymmetrical(BinaryTreeNode* pRoot){ return isSymmetrical(pRoot, pRoot);}bool isSymmetrical(BinaryTreeNode* pRoot1, BinaryTreeNode* pRoot2){ if(pRoot1 == nullptr && pRoot2 =...

2018-03-17 09:52:31 146

转载 树的子结构

题目:输入两棵二叉树A和B,判断B是不是A的子结构struct BinaryTreeNode{ double m_dbValue; BinaryTreeNode* m_pLeft; BinaryTreeNode* m_pRight;};bool DoesTree1HaveTree2(BinaryTreeNo...

2018-03-17 09:47:48 149

转载 正则表达式

// 题目:请实现一个函数用来匹配包含'.'和'*'的正则表达式。模式中的字符'.' // 表示任意一个字符,而'*'表示它前面的字符可以出现任意次(含0次)。在本题 // 中,匹配是指字符串的所有字匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a" // 和"ab*ac*a"匹配,但与"aa.a"及"ab*a"均不匹配。bool match(const char* st...

2018-03-17 00:39:24 126

转载 删除链表中重复的结点

题目:在一个排序的链表中,如何删除重复的结点void DeleteDuplication(ListNode** pHead){ if(pHead == nullptr || *pHead == nullptr) return; ListNode* pPreNode = nullptr; ListNode* pNode = *pHead; whil...

2018-03-17 00:14:21 289

转载 数的开方的计算方法

67081的平方根=259 算法1: 假设被开放数为a,如果用sqrt(a)表示根号a 那么((sqrt(x)-sqrt(a/x))^2=0的根就是sqrt(a) 变形得 sqrt(a)=(x+a/x)/2 所以你只需设置一个约等于(x+a/x)/2的初始值,代入上面公式,可以得到一个更加近似的值,再将它代入,就得到一个更加精确的值……依此方法,最后得到一个足够精度的(x+a/x)/2的值。 如:...

2018-03-17 00:06:16 2706

转载 数值的整数次方

bool g_InvalidInput = false;bool equal(double num1, double num2);double PowerWithUnsignedExponent(double base, unsigned int exponent);double Power(double base, int exponent){ g_InvalidInput =...

2018-03-16 23:32:47 188 1

原创 C++的大端口和小端口

int main(int argc, char **argv){ short int x; char x0,x1; x=0x1122; x0=((char*)&x)[0]; //低地址单元 x1=((char*)&x)[1]; //高地址单元 cout<<hex<<(int)x0<&lt...

2018-03-16 19:11:08 736

转载 225. Implement Stack using Queues

Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whether ...

2018-03-15 21:05:40 103

转载 232. Implement Queue using Stacks

Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty() --...

2018-03-15 20:58:58 89

转载 const_cast

const_cast是一种C++运算符,主要是用来去除复合类型中const和volatile属性(没有真正去除)。变量本身的const属性是不能去除的,要想修改变量的值,一般是去除指针(或引用)的const属性,再进行间接修改。用法:const_cast<type>(expression)通过const_cast运算符,也只能将const type*转换为type*,将const ty...

2018-03-15 10:24:55 102

转载 static关键字

(1)设置变量的存储域,函数体内static变量的作用范围为该函数体,不同于auto变量,该变量的内存只被分配一次,因此其值在下次调用时仍维持上次的值;(2)限制变量的作用域,在模块内的static全局变量可以被模块内所用函数访问,但不能被模块外其它函数访问;(3)限制函数的作用域,在模块内的static函数只可被这一模块内的其它函数调用,这个函数的使用范围被限制在声明它的模块内;(4)在类中的s...

2018-03-15 09:57:41 98

转载 二叉树中和为某一值的路径

输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。void findPath(BinaryTreeNode* root,int expectedNum,vector<int>& path,int& currentSum){ currentSum+=root->va...

2018-03-15 08:39:42 95

转载 旋转数组的最小数

把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。 public static int minNumberInRotateArray(int [] array) { ...

2018-03-15 08:34:03 154

原创 void *指针加法

#include <iostream>#include <stdio.h>#include <stdint.h>using namespace std;int main(int argc, char **argv){ uint32_t arr[3] = {0x01020304,1,2}; void *p = arr; voi...

2018-03-14 18:03:16 3287

转载 33. Search in Rotated Sorted Array

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the a...

2018-03-14 09:15:37 121

转载 414. Third Maximum Number

Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Input: [3, 2, 1]Out...

2018-03-14 08:45:04 124

原创 215. Kth Largest Element in an Array

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.Note: Y...

2018-03-14 08:32:24 150

转载 208. Implement Trie (Prefix Tree)

Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.class TrieNode{public: char content; bool is_end; int...

2018-03-14 08:19:36 149

原创 树相关算法

判断二叉树的后序遍历序列多叉树的构建二叉树中和为某一值的路径树的子结构对称的二叉树二叉搜索树与双向链表之字形打印二叉树分行从上到下打印二叉树树的子结构208. Implement Trie (Prefix Tree)根据先序遍历和中序遍历构建二叉树Tree Mirror output二叉树系列——二叉树的最大距离297. Serialize and Deserialize Binary Tree2...

2018-03-13 21:35:15 148

转载 往链表末尾插入节点,删除链表中含有某个值的节点

void AddToTail(ListNode ** pHead,int value) { ListNode * pNew=new ListNode(); pNew->m_nValue=value; pNew->m_pNext=NULL; if(*pHead==NULL) { *pHead=pNe...

2018-03-12 21:30:01 271

原创 链表相关算法

在O(1)时间删除链表结点从尾打印到头链表中倒数第k个节点删除链表中值重复的节点往链表末尾插入节点,删除链表中含有某个值的节点21. Merge Two Sorted Lists160. Intersection of Two Linked Lists142. Linked List Cycle II141. Linked List Cycle86. Partition List92. Rever...

2018-03-12 21:18:48 319

转载 最长回文子串的Manacher算法

 manacher算法(民间称马拉车算法233)是用来找字符串中的最长回文子串的,先来说一下什么是回文串,像这样“abcba”这样一个字符串找到一个中间位置,然后分别向他的左边和右边相等的距离位置的字符是相同的,那么这个字符串就称为回文串,“abcba”这个字符串的len为5是奇数,我们可以找到一个中间字符,然后进行搜索也可以找出来(当然时间复杂度是比较高的),但是当我们遇到一个长度为偶数的字符串...

2018-03-12 21:06:49 264

转载 数组重复数字 不修改数组

#include <iostream>#include <cstdlib>#include <stdio.h>//数组长度n+1,内容为1到n的数字,有重复//二分法 数组中重复数字 不能修改数组内容 时间复杂度O(nlogn) 空间复杂度O(1)int count(int* numbers,int length,int start,int end...

2018-03-11 22:15:08 153

转载 数组中重复的数字

题目描述在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重复的。也不知道每个数字重复几次。请找出数组中任意一个重复的数字。 例如,如果输入长度为7的数组{2,3,1,0,2,5,3},那么对应的输出是重复的数字2或者3。class Solution {public: // Parameters: // numbe...

2018-03-11 22:12:29 131

转载 二维数组中的查找

题目描述在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 输入描述:array: 待查找的二维数组arrget:查找的数字输出描述:查找到返回true,查找不到返回false我是从右上角开始差找的。但有两点没考虑到一:while循环中是 && 还是 ||,只有当co...

2018-03-11 22:09:44 193

转载 两个有序数据合并,不申请新的数组

有两个排序数组A1和A2,内存在A1的末尾有足够多的空余空间容纳A2,实现一个函数,把A2 插入到A1,并且是有序的。/*有两个排序数组A1和A2,内存在A1的末尾有足够多的空余空间容纳A2,实现一个函数,把A2插入到A1,并且是有序的。*/#include <iostream>using namespace std;void fun(int a[],int len1,in...

2018-03-11 22:05:27 656

空空如也

空空如也

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

TA关注的人

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