- 博客(122)
- 资源 (2)
- 收藏
- 关注
翻译 [stackoverflow]哈希表是如何工作的?
原地址:http://stackoverflow.com/questions/730620/how-does-a-hash-table-workLane正文: 这是一个对于外行的解释. 让我们假设你不仅想要用书填满图书馆,还想当你需要就很容易的找到他们. 所以,你觉得如果一个人想要读一本书,需要知道这书的确切书名去寻找,应该可以找到书.一个人有书名+图书管
2015-06-12 14:47:15
929
原创 [LeetCode]-012-Integer to Roman
网址:https://leetcode.com/problems/integer-to-roman/题意:模拟题...自己去查罗马数字怎么转化的就ok.代码:https://github.com/LiLane/leetcode/blob/master/java/012-IntegertoRoman-201505181637.javahttps://github.com/Li
2015-05-18 16:40:16
865
原创 [LeetCode]-011-Container With Most Water
网址:https://leetcode.com/problems/container-with-most-water/题意:找两条纵深线,然后利用x坐标来计算容器面积.分析:先找最远的两头,然后往中间收缩,长变小了,高变长才能使面积可能更大.所以就是找更长的...解法:如果height[left]反之,同理.代码:https://github.com/L
2015-05-18 16:16:11
810
原创 [LeetCode]-010-Regular Expression Matching
网址:https://leetcode.com/problems/regular-expression-matching/题意:输入的字符串是否被规则序列完全覆盖.其中 . 代表一个任意字符其中 * 代表任意个任意字符分析:其实就是对正则的一部分实现.都是很实用的技能和技巧.难点在于对于*的取舍.*可以是0,也可以是任意值,但却未必是最大值.尝试用迭代法做.
2015-05-18 15:24:05
857
翻译 介绍Redis
英文原文:http://redis.io/topics/introduction#introduction-to-redis Redis是一个开源的,遵循BSD license的高性能键值缓存和存储.它经常被当作一个数据结构服务器,支持的数据类型包括strings,hashes,lists,sets,sorted sets,bitmaps和hyperloglogs. 你可以运行
2015-05-18 11:00:34
738
原创 字符流中第一个不重复的字符
class Solution{public: int num[256]; int index; Solution(){ for(int i = 0; i < 256; i++) num[i] = -1; index = 0; } //Insert one char from stringstream vo
2015-05-05 21:08:24
572
原创 表示数值的字符串
class Solution {public: bool isNumeric(char* string) { if(string == NULL) return false; if(*string == '+' || *string == '-') string++; if(*string == '\0')
2015-05-05 16:20:30
750
原创 正则表达式匹配
class Solution {public: bool match(char* str, char* pattern){ if(str == NULL || pattern == NULL) return false; return matchCore(str,pattern); } bool matchCore(char* s
2015-05-05 10:20:50
690
原创 构建乘积数组
class Solution {public: vector multiply(const vector& A) { vector result; if(A.size() == 0) return result; result.push_back(1); int temp = 1; for(int i
2015-05-04 23:09:42
1032
原创 数组中重复的数字
class Solution {public: // Parameters: // numbers: an array of integers // length: the length of array numbers // duplication: (Output) the duplicated number in the
2015-05-04 22:10:23
731
原创 把字符串转换成整数
class Solution {public: int StrToInt(string str) { if(str.length() == 0) return 0; bool flag = true; int k = 0; if(str[0] == '+'){ k++; }els
2015-05-04 17:02:50
768
原创 不用加减乘除做加法
class Solution {public: int Add(int num1, int num2) { int sum,carry; do{ sum = num1 ^ num2; carry = (num1 & num2) << 1; num1 = sum;
2015-05-04 16:47:47
540
原创 求1+2+3+...+n
class Temp{public: Temp(){ N++; sum += N; } static int getResult(){ return sum; } static void reset(){ N = 0; sum = 0; }private: s
2015-05-04 13:25:36
893
原创 孩子们的游戏(圆圈中最后剩下的数)
class Solution {public: int LastRemaining_Solution(unsigned int n, unsigned int m) { if(n < 0 || m < 1) return -1; int last = 0; for(int i = 2; i <= n; i ++){
2015-05-03 23:41:44
590
原创 扑克牌顺子
class Solution {public: bool IsContinuous( vector numbers ) { int special = 0; bool flag = false; int last; sort(numbers.begin(),numbers.end()); for(int i = 0; i <
2015-05-03 22:52:14
653
原创 翻转单词顺序列
class Solution {public: void ReVerse(string &str,int start,int end){ if(str.length() == 0) return; while(start < end){ char c = str[start];
2015-05-03 22:39:54
493
原创 左旋转字符串
class Solution {public: string LeftRotateString(string str, int n) { if(str.length() == 0) return ""; n = n % str.length(); string left = str.substr(n,str.length()-n);
2015-05-03 21:23:48
449
原创 和为S的连续正数序列
class Solution {public: vector > FindContinuousSequence(int sum) { int small = 1; int big = 2; int num = small + big; vector > result; while(small * 2 <= sum){
2015-05-03 21:16:17
422
原创 和为S的两个数字
class Solution {public: vector FindNumbersWithSum(vector array,int sum) { int head = 0; int tail = array.size() - 1; vector result; while(head < tail){ if(array
2015-05-03 16:17:46
474
原创 数组中只出现一次的数字
class Solution {public: void FindNumsAppearOnce(vector data,int* num1,int *num2) { if(data.size() < 2){ *num1 = 0; *num2 = 0; return; } int num
2015-05-03 14:44:09
518
原创 平衡二叉树
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: bool IsBalanced(TreeNode*
2015-05-03 13:50:49
465
原创 二叉树的深度
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: int max = 0; void Tree
2015-05-03 12:06:26
386
原创 数字在排序数组中出现的次数
class Solution {public: int first = -1; int last = -1; bool flag = false; void findK(vector data,int k,int start,int end){ if(start > end || flag) return;
2015-05-03 11:58:55
543
原创 两个链表的第一个公共结点
/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: int GetLength(ListNode* head){ int len = 0; while(head
2015-05-03 11:33:06
439
原创 数组中的逆序对
class Solution {public: vector copyData; vector data; int InversePairsCore(int start,int end){ if(start == end){ copyData[start] = data[start]; return 0;
2015-05-03 11:20:03
521
原创 第一个只出现一次的字符
class Solution {public: int FirstNotRepeatingChar(string str) { map m; int num[256]; int pos[256]; int k = 0; for(int i = 0; i < 256; i++) pos[i] = -1;
2015-05-02 22:57:04
404
原创 丑数
class Solution {public: int Min(int n1,int n2,int n3){ int min = (n1 < n2) ? n1 : n2; min = (min < n3) ? min : n3; return min; } int GetUglyNumber_Solution(int i
2015-05-02 22:32:42
387
原创 把数组排成最小的数
class Solution {public: bool com(string s,string st){ int i; for(i = 0; i < s.length() && i < st.length(); i++){ if(s[i] > st[i]) return true;
2015-05-02 22:12:18
375
原创 整数中1出现的次数(从1到n整数中1出现的次数)
class Solution {public: int NumberOf1Between1AndN_Solution(int n) { int nCurBit = n % 10; int nForward = n / 10; int nBackward = 0; int nBase = 1; int nSum = 0;
2015-05-02 21:06:52
480
原创 连续子数组的最大和
class Solution {public: int FindGreatestSumOfSubArray(vector array) { if(array.size() == 0) return 0; int num = 0; int max = INT_MIN; for(int i = 0; i < array.s
2015-05-02 20:15:09
379
原创 最小的K个数
class Solution {public: vector GetLeastNumbers_Solution(vector input, int k) { vector result; if(input.size() < k) return result; sort(input.begin(),input.end());
2015-05-02 20:08:46
433
原创 数组中出现次数超过一半的数字
class Solution {public: int MoreThanHalfNum_Solution(vector numbers) { if(numbers.size() == 0) return 0; map m; for(int i = 0; i < numbers.size(); i++){ if(
2015-05-02 20:00:20
377
原创 字符串的排列
class Solution {public: vector v; int leng = 0; void buildString(string s,char c[],int len,bool flag[]){ if(len == leng){ for(int i = 0; i < v.size(); i++)
2015-05-02 19:39:36
411
原创 二叉搜索树与双向链表
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: TreeNode* ConvertNode(Tree
2015-05-02 16:10:51
475
原创 复杂链表的复制
/*struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : label(x), next(NULL), random(NULL) { }};*/class Solution {public: RandomListNode* Clone(
2015-05-02 14:38:02
473
原创 二叉树中和为某一值的路径
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: int num = 0; vector >
2015-05-02 13:35:31
445
原创 二叉搜索树的后序遍历序列
class Solution {public: bool VerifySquenceOfBST(vector sequence) { int len = sequence.size(); if(len == 0) return false; if(len == 1) return true; v
2015-05-02 12:34:07
438
原创 从上往下打印二叉树
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: vector PrintFromTopToBottom(T
2015-05-02 12:01:25
511
原创 栈的压入、弹出序列
class Solution {public: bool IsPopOrder(vector pushV,vector popV) { stack s; int k = 0; for(int i = 0; i < pushV.size(); i++){ if(pushV[i] != popV[k]){
2015-05-02 11:46:31
473
原创 包含min函数的栈
class Solution {public: stack s; stack minS; void push(int value) { if(minS.size() == 0 || value < minS.top()) minS.push(value); s.push(value); } void pop() { if(s.
2015-05-01 21:19:48
346
NeHe的教程及源码(OpenGL教程)
2014-12-01
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人