05 2014 档案

leetcode -- Best Time to Buy and Sell Stock II
摘要:class Solution {public: int maxProfit(vector &prices) { if(prices.size() == 0) return 0; vector f(prices.size()); f[0] = 0; ... 阅读全文

posted @ 2014-05-28 21:18 berkeleysong 阅读(141) 评论(0) 推荐(0)

leetcode -- Best Time to Buy and Sell Stock
摘要:class Solution {public: int maxProfit(vector &prices) { if(prices.size() == 0) return 0; vector f1(prices.size()); int minV = pri... 阅读全文

posted @ 2014-05-28 21:02 berkeleysong 阅读(104) 评论(0) 推荐(0)

Add Two Numbers
摘要:class Solution {public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { if(NULL == l1) return l2; if(NULL == l2) return l1; ... 阅读全文

posted @ 2014-05-28 20:21 berkeleysong 阅读(181) 评论(0) 推荐(0)

leetcode -- Add Binary
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".class Solution {public: string addBinary(str... 阅读全文

posted @ 2014-05-28 12:15 berkeleysong 阅读(146) 评论(0) 推荐(0)

leetcode -- 4sum
摘要:class Solution {public: vector > ret; vector subret;public: vector > fourSum(vector &num, int target) { sort(num.begin(),num.end()); ... 阅读全文

posted @ 2014-05-28 11:12 berkeleysong 阅读(140) 评论(0) 推荐(0)

leecode -- 3sum Closet
摘要:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文

posted @ 2014-05-28 10:32 berkeleysong 阅读(206) 评论(0) 推荐(0)

C++单例模式
摘要:单例模式是一种常用的软件设计模式。在它的核心结构中只包含一个被称为单例类的特殊类。通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问,从而方便对实例个数的控制并节约系统资源。如果希望在系统中某个类的对象只能存在一个,单例模式是最好的解决方案。#include#include#i... 阅读全文

posted @ 2014-05-27 16:22 berkeleysong 阅读(174) 评论(0) 推荐(0)

MapReduce的模式、算法和用例
摘要:在这篇文章里总结了几种网上或者论文中常见的MapReduce模式和算法,并系统化的解释了这些技术的不同之处。所有描述性的文字和代码都使用了标准hadoop的MapReduce模型,包括Mappers, Reduces, Combiners, Partitioners,和 sorting。如下图所示。... 阅读全文

posted @ 2014-05-27 13:28 berkeleysong 阅读(372) 评论(0) 推荐(0)

leetcode -- 3sum
摘要:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen... 阅读全文

posted @ 2014-05-27 13:13 berkeleysong 阅读(188) 评论(0) 推荐(0)

重点算法--合并排序
摘要:#includeusing namespace std; void merge(int left,int mid,int right,int a[],int b[]){ int i = 0; int cursor1 = left; int cursor2 = mid +1; while(cu... 阅读全文

posted @ 2014-05-27 11:40 berkeleysong 阅读(215) 评论(0) 推荐(0)

重点算法--快速排序
摘要:#includeusing namespace std;////写出快速排序,归并排序与堆排序int adjustarray(int a[],int left,int right){ int x = a[left]; while(left x && left < right) righ... 阅读全文

posted @ 2014-05-27 10:24 berkeleysong 阅读(168) 评论(0) 推荐(0)

邻接表广度深度遍历
摘要:#include#includeusing namespace std;const int MaxVertexNum = 100; bool visited[MaxVertexNum];int relationNonDir[][2] = {{0,1},{0,2},{1,2},{1,3},{2,6},... 阅读全文

posted @ 2014-05-25 13:12 berkeleysong 阅读(264) 评论(0) 推荐(0)

判断是否AVL平衡二叉书
摘要:#include#include#include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():va... 阅读全文

posted @ 2014-05-23 16:01 berkeleysong 阅读(283) 评论(0) 推荐(0)

用递归方法判断两棵树是否相等
摘要:#include#include#include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():va... 阅读全文

posted @ 2014-05-23 11:59 berkeleysong 阅读(637) 评论(0) 推荐(0)

广度优先搜索求树的深度
摘要:#include#include#include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():va... 阅读全文

posted @ 2014-05-23 11:34 berkeleysong 阅读(256) 评论(0) 推荐(0)

堆排序
摘要:#include#include#includeusing namespace std; //void MinHeapFixup(int a[], int i)//{// int j ,temp;// temp = a[i];// j = (i-1)/2;// while(j >= 0 && i !... 阅读全文

posted @ 2014-05-23 10:50 berkeleysong 阅读(177) 评论(0) 推荐(0)

归并排序
摘要:#includeusing namespace std;///算法重要,但是思想更重要 void MemeryArray(int a[],int n,int b[],int m,int c[])///经典框架,be careful!{ int i,j,k; i = j = k = 0; while(... 阅读全文

posted @ 2014-05-23 09:49 berkeleysong 阅读(238) 评论(0) 推荐(0)

伤心的快排
摘要:#includeusing namespace std;///快排,百度数据挖掘,我面到终面///他们部门经理过来面我///数据挖掘的东西,兵来将挡,水来土掩////讲完项目于对互联网的理解///他说,最后写个快排吧~~~~////FUCK,我没写出来////嚓嚓嚓嚓嚓int AdjustArray... 阅读全文

posted @ 2014-05-22 21:31 berkeleysong 阅读(144) 评论(0) 推荐(0)

广度优先搜索
摘要:#include#include#include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():va... 阅读全文

posted @ 2014-05-22 20:40 berkeleysong 阅读(107) 评论(0) 推荐(0)

C++ 复制控制
摘要:在定义一个新类型的时候,一般要显示或者隐式的制定复制,赋值和撤销该类型的对象会发生什么复制够着函数,赋值操作函数和析构函数1.复制构造函数C++支持两种初始化方式,直接初始化,复制初始化。如果想防止复制,就可以将其复制构造函数声明为private大多数类应该定义复制构造函数和默认构造函数2.赋值操作... 阅读全文

posted @ 2014-05-22 18:47 berkeleysong 阅读(137) 评论(0) 推荐(0)

C++ primer 第十二章
摘要:在类内部定义的函数默认为inline函数后面加const,不能改变操作对象的数据成员,const必须在定义和声明的时候都存在,否则会出现编译错误类和结构体,还有枚举是怎么实现的,内存是如何存储的,这是个大问题?因为只有当类定义体完成后才能定义类,因此类不能具有自身类型的数据与成员,然而只要类名一出现... 阅读全文

posted @ 2014-05-22 18:28 berkeleysong 阅读(107) 评论(0) 推荐(0)

前序中序后序遍历非递归实现
摘要:#include#include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():val(0),lef... 阅读全文

posted @ 2014-05-22 17:58 berkeleysong 阅读(269) 评论(0) 推荐(0)

用递归做的前序中序后序遍历
摘要:#include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():val(0),left(NULL),... 阅读全文

posted @ 2014-05-22 16:14 berkeleysong 阅读(166) 评论(0) 推荐(0)

不同元素的排列与组合
摘要:#include#include#include#include#includeusing namespace std; vector > ret;vector sub;int num = 0;void helper(int* str, int n,int i) ///递归求组合{ if(i ==... 阅读全文

posted @ 2014-05-21 17:59 berkeleysong 阅读(226) 评论(0) 推荐(0)

两种字符串逆序的方法
摘要:#include#include#include#includeusing namespace std;void helper(char* str) ///用指针实现,注意strlen的用法,并且没有动最后的\0{ int len = strlen(str); int pleft = 0; i... 阅读全文

posted @ 2014-05-21 13:22 berkeleysong 阅读(175) 评论(0) 推荐(0)

递归合并链表~
摘要:#include#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;... 阅读全文

posted @ 2014-05-21 12:36 berkeleysong 阅读(246) 评论(0) 推荐(0)

使用map做数组与链表去重
摘要:#include#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;... 阅读全文

posted @ 2014-05-21 10:51 berkeleysong 阅读(507) 评论(0) 推荐(0)

链表有环检测,环长度,环开始的地方
摘要:#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;node* cr... 阅读全文

posted @ 2014-05-21 09:43 berkeleysong 阅读(199) 评论(0) 推荐(0)

友元函数 C++
摘要:#include#includeusing namespace std;class Text{public: Text():a(1){}private: int a; void display(){ cout<< "hello world"<<endl;} friend vo... 阅读全文

posted @ 2014-05-20 14:46 berkeleysong 阅读(213) 评论(0) 推荐(0)

C++杂分析
摘要:class word{public: word(){cout#includeusing namespace std;class Text{public: static const int a = 1; ///static 数据成员独立与该类存在 ///static int b = ... 阅读全文

posted @ 2014-05-20 14:22 berkeleysong 阅读(145) 评论(0) 推荐(0)

求链表的中心节点
摘要:#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;node* cr... 阅读全文

posted @ 2014-05-19 19:57 berkeleysong 阅读(177) 评论(0) 推荐(0)

链表的递归运算
摘要:#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;node* cr... 阅读全文

posted @ 2014-05-19 19:43 berkeleysong 阅读(189) 评论(0) 推荐(0)

逆序链表
摘要:#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;node* cr... 阅读全文

posted @ 2014-05-19 19:34 berkeleysong 阅读(188) 评论(0) 推荐(0)

找到链表的倒数第K位
摘要:#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;node* cr... 阅读全文

posted @ 2014-05-19 16:32 berkeleysong 阅读(180) 评论(0) 推荐(0)

链表的增删(未考虑末尾)
摘要:#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;node* cr... 阅读全文

posted @ 2014-05-19 16:21 berkeleysong 阅读(195) 评论(0) 推荐(0)

计算出前N项的数据
摘要:#include#include#includeusing namespace std;const int N = 10;int helper(int* a,const int num1,const int num2){ int i=1; int j=1; for(int m = 0;m te... 阅读全文

posted @ 2014-05-19 11:52 berkeleysong 阅读(116) 评论(0) 推荐(0)

将后面的m个数移到前面
摘要:#include#include#include#includeusing namespace std;int bigswap(char* a,int start,int end){ while(start<end) { swap(a[start],a[end]); ... 阅读全文

posted @ 2014-05-19 11:34 berkeleysong 阅读(210) 评论(0) 推荐(0)

获得第二大的元素
摘要:#includeusing namespace std;int main(){ int s1 = 1; unsigned int s2 = 1; cout>和逻辑右移(不带符号)>>>。 //算术右移:符号位不变,左边补上符号位。如: 1000 1000 >> 3 为 1111 0001 //逻辑右... 阅读全文

posted @ 2014-05-19 10:44 berkeleysong 阅读(193) 评论(0) 推荐(0)

数组祛除重复
摘要:#include#include#includeusing namespace std;void helper(int a[],const int n){ sort(a,a+n); int k = 0; for(int i = 0;i< n;i++) { if(a[i] != a[k])... 阅读全文

posted @ 2014-05-18 22:47 berkeleysong 阅读(103) 评论(0) 推荐(0)

左边为奇数,右边为偶数
摘要:#include#include#includeusing namespace std;void helper(int a[],const int n){ int left = 0; int right = n-1; while(leftleft) right--; ... 阅读全文

posted @ 2014-05-18 22:02 berkeleysong 阅读(177) 评论(0) 推荐(0)

找到符合条件的对数
摘要:#include#include#includeusing namespace std;int helper(int a[],int n, int t){ sort(a,a+n); int k = 0; int left = 0; int right = n-1; while(left t... 阅读全文

posted @ 2014-05-18 21:44 berkeleysong 阅读(132) 评论(0) 推荐(0)

找出出现奇数次的元素
摘要:#includeusing namespace std;bool question1(const int a[],const int n, int &num){ int temp = 0; for(int i = 0;i>1; k++; } num1 = 0; ... 阅读全文

posted @ 2014-05-18 21:24 berkeleysong 阅读(218) 评论(0) 推荐(0)

找到数组中唯一重复的数
摘要:#include#include#includeusing namespace std;int helper1(int a[],int n){ int sum = accumulate(a,a+n,0); int sum2 = n*(n-1)/2; return sum-sum2;}int h... 阅读全文

posted @ 2014-05-18 19:52 berkeleysong 阅读(188) 评论(0) 推荐(0)

在O(n)时间复杂度内找到出现超过一半的数
摘要:#includeusing namespace std;bool solver(const int a[],const int n, int & num){ if(NULL == a || 0>= n) return false; ////注意,是小写~ int count = 0; ... 阅读全文

posted @ 2014-05-18 19:29 berkeleysong 阅读(142) 评论(0) 推荐(0)

寻找数组中重复次数最多的数
摘要:#include#includeusing namespace std;int helper(const int a[],const int n){ map m; for(int i = 0;i::iterator comp = m.begin(); for( map::iterator it... 阅读全文

posted @ 2014-05-18 18:40 berkeleysong 阅读(245) 评论(0) 推荐(0)

第十一章 泛型算法 C++ PRIMER
摘要:vector::const_iterator result = find(vector.begin(). vector.end(),search_value); 如果查找失败,分会end() 如果有两个,会返回哪一个的迭代器?int *reauslt = find(ia,ia+6,search_va... 阅读全文

posted @ 2014-05-18 14:32 berkeleysong 阅读(144) 评论(0) 推荐(0)

动态规划题目
摘要:动态规划算法,在T大某位老师的书中说就是递推+重复子问题。动态规划算法的效率主要与重复子问题的处理有关。典型的题目有 陪审团,最大公共子串问题1,最大公共子串问题这个是动态规划的基础题目。动态规划就是递推和重复子结构。确定了递推关系后。找到一个能极大地减少重复运算的子结构至关重要。选的好了,时间效率... 阅读全文

posted @ 2014-05-17 20:48 berkeleysong 阅读(251) 评论(0) 推荐(0)

C++ primer 第十章
摘要:关联容器,完全没用过,一直想用,FUC,本文只介绍初级使用方式,不能贪多#include#include#include#includeusing namespace std;typedef pair Auth;int main(){ map m; set s; Auth p1,p2,p3,p4; ... 阅读全文

posted @ 2014-05-17 20:31 berkeleysong 阅读(150) 评论(0) 推荐(0)

C++ PRIMER 第九章
摘要:顺序容器:vector list deque顺序容器适配器: stack queue priority_quequ(没见过,第一轮不管)C c; C c(c2); C c(b,e) ///b e 都是迭代器; c(n,t)///只用于顺序容器; C c(n) ///只用于顺序容器const list... 阅读全文

posted @ 2014-05-17 19:34 berkeleysong 阅读(187) 评论(0) 推荐(0)

二分查找 变形
摘要:#includeusing namespace std;int helper(int a[],int len,int t,bool isleft){ if(a == NULL || 0 >= t) return EOF; int last = EOF; int left = 0; ... 阅读全文

posted @ 2014-05-17 12:59 berkeleysong 阅读(97) 评论(0) 推荐(0)

二分查找法
摘要:#includeint BinarySearch(const int a[],const int t,int lengh) ///暂时没错的版本,注意middle最好不要直接赋值,因为那样如果找不到,会引起死循环{ printf("%d",sizeof(a));///放到这里输出为4 int s... 阅读全文

posted @ 2014-05-17 12:09 berkeleysong 阅读(148) 评论(0) 推荐(0)

Logistic 回归模型 第一遍阅读笔记
摘要:MLE :最大似然估计,求得的这套参数估计能够通过指定模型以最大概率在线样本观测数据必须来自随机样本,自变量与因变量之间是线性关系logistic 回归没有关于自变量分布的假设条件,自变量可以连续,也可以离散,不需要假设他们之间服从多元正太分布,当然如果服从,效果更好logistic 回归对多元共线... 阅读全文

posted @ 2014-05-17 12:02 berkeleysong 阅读(427) 评论(0) 推荐(0)

C++PRIMER 阅读笔记 第三章
摘要:本章主要介绍 string vector 和 bitset, 不能贪多,现在本文主要介绍 string 与 vector头文件中最好不要使用namespace std, 因为头文件会直接被预处理器放置到C中std::string 的构造方式: string s1; string s2(s1); st... 阅读全文

posted @ 2014-05-16 16:49 berkeleysong 阅读(146) 评论(0) 推荐(0)

一个for循环打印二维数组
摘要:#include#define MAXX 2#define MAXY 3void printarray(){ int Arr[MAXX][MAXY] = {1,2,3,4,5,6}; for(int i = 0;i< MAXX*MAXY;i++) { printf("%d\... 阅读全文

posted @ 2014-05-16 11:00 berkeleysong 阅读(329) 评论(0) 推荐(0)

递归实现数组求和
摘要:#includeint sum(int* a, int n){ return (0 == n)?0:(sum(a,n-1) + a[n-1]);}void sum1(int* a, int n,int& s){ if(0 == n) return; else {... 阅读全文

posted @ 2014-05-16 10:51 berkeleysong 阅读(349) 评论(0) 推荐(0)

strlen 与 sizeof
摘要:#include#include#include#includeusing namespace std;int main(){ int a[] = {1,2,3,4,5}; int* b = a; char c[] = {'a','c','c'}; char* d = c; char e[] = "... 阅读全文

posted @ 2014-05-16 10:13 berkeleysong 阅读(133) 评论(0) 推荐(0)

导航