自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Pilgrim

希望某一天跪在那片向往的圣地,满含热泪,亲吻大地,将那之前所经历的种种痛苦,笑着说出来......

  • 博客(29)
  • 资源 (1)
  • 收藏
  • 关注

原创 LeetCode 71. Simplify Path

https://leetcode.com/problems/simplify-path/其实就是练习字符串处理吧 以前没有用过erase函数,总结下用法:#include #include #include #include #include #include #include using namespace std;int main() {

2016-01-26 00:28:06 306

原创 LeetCode 64. Minimum Path Sum

https://leetcode.com/problems/minimum-path-sum/dp 很简单const int SIZE = 1001;class Solution {public: int minPathSum(vector >& grid) { int m = grid.size(), n=grid[0].size(); //

2016-01-25 22:59:26 309

原创 LeetCode 69. Sqrt(x)

https://leetcode.com/problems/sqrtx/二分法class Solution {public: int mySqrt(int x) { if(x <= 1) return x; int l = 0 ,r = x, mid= (l+r)/2;; while(l <= r) { /

2016-01-25 22:57:50 305

原创 LeetCode 63. Unique Paths II

https://leetcode.com/problems/unique-paths-ii/比http://blog.csdn.net/u011026968/article/details/50582964  多一步 就是有障碍的地方有0种方法const int SIZE = 101;class Solution {public: int uniquePat

2016-01-25 21:02:24 356

原创 *LeetCode 62. Unique Paths 记忆化搜索 or 组合数学

https://leetcode.com/problems/unique-paths/记忆化搜索的本质就是dp, 但是涉及图的时候 有时候思考会更顺一些const int SIZE = 101;class Solution {public: int uniquePaths(int m, int n) { for(int i=0;i<m;i+

2016-01-25 20:56:24 505

原创 LeetCode 61. Rotate List

https://leetcode.com/problems/rotate-list/一直想给LeetCode 的题目描述跪, 一直说不清楚。此题一个坑是:k >= length(链表),只要k%=n就行,当然这个时候还有坑 n==0#include #include #include #include #include #include #include using n

2016-01-25 00:39:39 310

原创 **LeetCode 60. Permutation Sequence

https://leetcode.com/problems/permutation-sequence/康拓展开和逆康拓展开自己推一推  参考http://www.cnblogs.com/hxsyl/archive/2012/04/11/2443009.htmlclass Solution {public: string getPermutation(int n, in

2016-01-23 02:04:36 303

原创 **LeetCode 56. Merge Intervals

https://leetcode.com/problems/merge-intervals/虽然是Hard  但是并不难,但是WA了问题在于 自己没有好好动手模拟,选择的分隔的标准有问题方法一:线段树涂色问题方法二:先把区间按照左端点排序 左端点一样就按照右端点排序,然后st en分别标记当前的区间,如果发现interval[i+1]>st 就存入ret,更新St和en

2016-01-23 01:26:39 403

原创 LeetCode 52. N-Queens II

https://leetcode.com/problems/n-queens-ii/跟上一题完全一样啊class Solution {public: int totalNQueens(int n) { int ret = 0; for(int i=0;i<n;i++) vis[i] = 0;

2016-01-22 22:26:52 329

原创 LeetCode 59. Spiral Matrix II

https://leetcode.com/problems/spiral-matrix-ii/#include #include #include #include #include #include #include using namespace std;class Solution {public: vector > generateMatrix(int

2016-01-22 02:38:56 338

原创 **LeetCode 54. Spiral Matrix

https://leetcode.com/problems/spiral-matrix/水题做成这个样子真是说不过去,,四个变量控制,两个控制左右范围,另个控制上下范围两种特殊情况,只有一行和一列,因为push_back的时候其实只是考虑了行或者列的情况没有综合考虑 所以容易重复#include #include #include #include #inc

2016-01-22 02:04:42 372

原创 LeetCode 51. N-Queens

https://leetcode.com/problems/n-queens/比较容易的hardDFS判断条件有点失误 哎DFS 写的有点慢啊class Solution {public: vector > solveNQueens(int n) { vector > ret; if(n == 0) return ret;

2016-01-22 01:24:11 432

原创 LeetCode 53. Maximum Subarray

https://leetcode.com/problems/maximum-subarray/dp题 很老了dp[i]是以i为结尾的和,那么当遍历到第i个数的时候,有两种选择,从i开始中心来,或者接着之前的dp[i-1]+nums[i]记录整个过程的最大值即可,O(n)话说  @博乐之后,,,我博客浏览量下降很惨啊 T_Tclass Solution

2016-01-21 23:51:46 503 2

原创 LeetCode 50. Pow(x, n)

https://leetcode.com/problems/powx-n/两个坑:(1)次方可以是赋值,解决方法是1/x(2)注意啊,如果n为负数的时候 右移运算,为了保持符号,符号位自动填充1,会TLE         另外还有坑  负的最大值比正的最大值大,所以一定转换long long啊class Solution {public: double

2016-01-21 22:36:14 372

原创 LeetCode 49. Group Anagrams

https://leetcode.com/problems/anagrams/拿来练一练multimap思路很简单,每个word都sort  然后根据这个结果决定放哪个multimap的元素学到multimap的遍历方法啊,有点麻烦class Solution {public: vector > groupAnagrams(vector& strs)

2016-01-21 01:21:56 433

原创 《从Paxos到ZooKeeper》读书笔记--两阶段提交 2PC

两种角色:参与者(Participant): 被调度的分布式节点协调者(Coordinator):同意调度所有分布式节点的执行逻辑,并最终决定参与者是否把事务真正进行提交。一、两个阶段        2PC就是把事务的提交郭晨共分为两个阶段进行处理        (1)提交事务请求                也

2016-01-13 12:22:31 1121

原创 *LeetCode 55. Jump Game

https://leetcode.com/problems/jump-game/做完Jump Game ii 才做的这个,所以直接就考虑O(n)做法#include #include #include #include #include using namespace std;class Solution {public: bool canJump(vec

2016-01-12 23:36:49 388

原创 **LeetCode 45. Jump Game II 思维题

https://leetcode.com/problems/jump-game-ii/这道题很不错,我的一种代码感觉本质上跟Ans一样,但是TLE....因为我的写法还是会有重复思路一:DP倒过来看,dp[lastIdx-1]=0,dp[i] = min(1+dp[i+k])   k=1,2....nums[i].果断TLEconst int MAX = 1

2016-01-12 22:18:04 382

原创 LeetCode 47. Permutations II

https://leetcode.com/problems/permutations-ii/这道题惊讶了一下,竟然超过了百分之94的cpp提交思路很简单next_permutation就行了。class Solution {public: vector > permuteUnique(vector& nums) { vector > ret;

2016-01-11 23:58:09 384

原创 LeetCode 46. Permutations DFS

https://leetcode.com/problems/permutations/这道题没啥说的 暴力DFS搞,也可以next_permutation#include #include #include #include #include using namespace std;const int SIZE = 1000+1;class Soluti

2016-01-11 23:52:46 393

原创 *LeetCode Wildcard Matching

https://leetcode.com/problems/wildcard-matching/方法一:DFS (需要开数组判重)这里我得承认,作弊了点,,因为有一组数据,长度4100左右两个字符串匹配。 所以开数组大小其实是WA了一次 然后才确定大小的,,,,想想为什么需要判重:s=aaaaap=a**adfs(s-2,p-2)可能通过多种途径到达,这样的话每种途

2016-01-10 00:10:43 419

原创 ***LeetCode 42. Trapping Rain Water

https://leetcode.com/problems/trapping-rain-water/最初思路是,用一个栈来存height,如果发现height[i] >= 栈顶 就计算一部分面积,时间复杂度似乎是O(n)然后发现最后部分很难处理,比如 4 2 3。。然后没有过,,这个在考虑下 。。很神奇的做法:从两头向中间扫描,找当前的第二高的地方。然后求小面积:

2016-01-09 20:59:49 411

原创 *LeetCode 41. First Missing Positive 思维题

https://leetcode.com/problems/first-missing-positive/如果是只缺一个数的话,好说,就是求和, 然后n*(n+1)/2 -sum  就是缺的数字但是,,,这道题,这样的数据也是要求有正确结果的:31 4 5这类题最终要的是:找到一些性质这个题需要理解的性质是,假设缺的数是ans,那么他应该出现在下标为ans-

2016-01-07 15:32:27 418

原创 *LeetCode 40. Combination Sum II

https://leetcode.com/problems/combination-sum-ii/跟39差不多 几分钟写写直接过const int SIZE = 1000+5;class Solution {public: vector > combinationSum2(vector& candidates, int target) { ans.clea

2016-01-05 09:33:32 446 1

原创 LeetCode 39. Combination Sum

https://leetcode.com/problems/combination-sum/去重,自己写比用STL set处理快一些哎,当初上交的保研复试题就是这个,这个第二题,第三题是一个不会的dp......const int SIZE = 1000+5;class Solution {public: void removeReplication(vector &

2016-01-05 09:30:40 366

原创 *LeetCode 31. Next Permutation

https://leetcode.com/problems/next-permutation/参考了STL源码剖析的做法。由尾部往前,找到连续的两个数ii=i+1  nums[i]从尾部往前,找到第一个j 满足 nums[j] > nums[i]将ii -> j 逆序即可class Solution {public: void nextPe

2016-01-04 00:26:33 332

原创 *Codeforces Round #337 (Div. 2) C Harmony Analysis 构造题

http://codeforces.com/contest/610/problem/C给一个数k,要求构造2^k个向量,着2^k个向量两两正交,向量维数为2^k思路:递归构造如果k=0,假设是1,k=11 11 -1也就是把前一个复制4分,右下角的为负值。这样的合理性很容易看出,。。#include #include #include usi

2016-01-03 23:07:02 500

原创 Codeforces Round #337 (Div. 2) A Pasha and Stick B Vika and Squares

http://codeforces.com/contest/610/problem/AA题 很简单,就是给出n 然后n分成四段,能组成长方形而不能组成正方形的情况数#include #include using namespace std;int main() { int n; while(cin >> n) { int ans ;

2016-01-03 22:59:15 535

原创 *LeetCode 29. Divide Two Integers

https://leetcode.com/problems/divide-two-integers/非常想知道有什么不用long long就可以A掉的方法,似乎没有我写的: 模拟除法,学过汇编应该很容易理解需要特殊判断的是:如果被除数是-2147483648const int MAX_INT = 2147483647;const int MIN_INT = -21474836

2016-01-03 21:27:53 477 1

演示数据结构的算法过程

帮助数据结构学习,用flash动画生动的演示数据结构的算法过程

2014-01-29

空空如也

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

TA关注的人

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