上一页 1 2 3 4 5 6 7 ··· 17 下一页
摘要: /*最大连续子序列*/class Solution {public: int maxSubArray(int A[], int n) { if(!n) return 0; int result = A[0],temp =0 ; for(int i = ... 阅读全文
posted @ 2015-04-11 15:09 SprayT 阅读(99) 评论(0) 推荐(0)
摘要: /*题意:有一排房子,每个房子里有一些钱,每两个相连房子只能取一个,问取得的最大的钱数是多少? */class Solution {public: int rob(vector &num) { int len = num.size(),num1 = 0,num2 = 0,temp... 阅读全文
posted @ 2015-04-11 14:59 SprayT 阅读(103) 评论(0) 推荐(0)
摘要: /*用两个栈,一个保存原始数据st,一个保存的是st中的一个有序的子序列*/class MinStack {public: stackmin,st; void push(int x) { if(min.empty()){ st.push(x); ... 阅读全文
posted @ 2015-03-31 13:41 SprayT 阅读(93) 评论(0) 推荐(0)
摘要: class Solution {public: int removeDuplicates(int A[], int n) { int temp = A[0],j = 0,count; for(int i = 0 ; i =2) A[j++] = temp; ... 阅读全文
posted @ 2015-03-29 21:44 SprayT 阅读(66) 评论(0) 推荐(0)
摘要: /*水题*/class Solution {public: int removeDuplicates(int A[], int n) { int temp = A[0],j = 0; for(int i = 0 ; i < n ;){ whil... 阅读全文
posted @ 2015-03-29 21:37 SprayT 阅读(87) 评论(0) 推荐(0)
摘要: /*写了个快排,但这肯定不是最优的解法,果然有O(n)的相当于快排的partition部分*/class Solution {public: void Qsort(int A[],int l,int r){ if(l>=r) return; int x = A[l]... 阅读全文
posted @ 2015-03-29 21:31 SprayT 阅读(122) 评论(0) 推荐(0)
摘要: /*简单二分*/class Solution {public: int searchInsert(int A[], int n, int target) { int l = 0,r = n-1,mid ; while(ltarget) r = mid-1; ... 阅读全文
posted @ 2015-03-29 20:34 SprayT 阅读(84) 评论(0) 推荐(0)
摘要: /* 简单dp,转态转移方程dp[i][j] = dp[i-1][j]+dp[i][j-1];初始化下边界*/class Solution {public: int uniquePaths(int m, int n) { if(m<0||n<0) return 0; ... 阅读全文
posted @ 2015-03-29 20:13 SprayT 阅读(85) 评论(0) 推荐(0)
摘要: /*异或的简单应用 a^a = 0*/class Solution {public: int singleNumber(int A[], int n) { int sum = 0; for(int i = 0 ; i < n ; i++){ s... 阅读全文
posted @ 2015-03-28 20:47 SprayT 阅读(90) 评论(0) 推荐(0)
摘要: /** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) :... 阅读全文
posted @ 2015-03-24 21:04 SprayT 阅读(104) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 17 下一页