摘要: No.146 LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(ke... 阅读全文
posted @ 2015-05-22 16:23 人生不酱油 阅读(206) 评论(0) 推荐(0)
摘要: No.35 Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would ... 阅读全文
posted @ 2015-05-22 10:42 人生不酱油 阅读(138) 评论(0) 推荐(0)
摘要: 最近编程需要对性能进行优化,看到VS2012自带的性能分析工具感觉超级赞,就在网上搜了一下,看到VS2012自带的性能分析工具使用实例写的非常不错,保存一下,值得一看。 阅读全文
posted @ 2015-05-07 09:06 人生不酱油 阅读(143) 评论(0) 推荐(0)
摘要: 最长公共子串是字符串匹配中一个常见问题,在此做下总结,感觉解法真的是很巧妙。 如:对于字符串“aabbaadcc”和“baadce”,矩阵中,m[i][j] = 1,表示str1[i]和str2[j]相等 a a b b a a d c c b 0 0 1 1 ... 阅读全文
posted @ 2015-04-03 14:58 人生不酱油 阅读(335) 评论(0) 推荐(0)
摘要: No.78 SubsetsGiven a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution se... 阅读全文
posted @ 2015-04-01 19:22 人生不酱油 阅读(133) 评论(0) 推荐(0)
摘要: No.22 Generate ParenthesesGivennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3,... 阅读全文
posted @ 2015-04-01 16:28 人生不酱油 阅读(257) 评论(0) 推荐(0)
摘要: 问:定义一个空类型,里面没有任何成员变量和成员函数,对该类型求sizeof,得到的结果为?答:1。问:为什么不是0?答:空类型的实例中不包含任何信息,本来求其sizeof应为0,但当声明该类型的实例时,它必须在内存中占有一定的空间,否则无法使用 这些实例。而其所占空间的大小,由编译器决定。VS中,... 阅读全文
posted @ 2015-03-31 17:15 人生不酱油 阅读(267) 评论(0) 推荐(0)
摘要: 在做leetcode的时候,又遇到这个百提不爽的问题,当时拿过题来,感觉那些情况我都知道的,然后就开始写。结果,还是很多没有注意到的,提交好几次才accept了,在此记录下,也与大家共享。 考虑情况:首先,传入指针是否为空字符串是否为空包含+、-符号【但仅包含+、-为非法的】是否会溢出(超出i... 阅读全文
posted @ 2015-03-31 15:49 人生不酱油 阅读(290) 评论(0) 推荐(0)
摘要: 算法思想:对n个数进行排序,需进行n-1趟排序,每次归位一个数。每次比较两个相邻的元素,如果他们的顺序错误,就把它们交换过来。复杂度:O(N2)优化:记录是否发生交换(true:是,false:否)算法代码: 1 #include "stdafx.h" 2 #include 3 #include ... 阅读全文
posted @ 2015-03-26 20:40 人生不酱油 阅读(145) 评论(0) 推荐(0)
摘要: 算法思想:每次在未排序的序列中找最大的数,将其放在未排序序列的最后位置,重复该过程,知道所有元素排序完毕。 算法代码: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 template 7 v... 阅读全文
posted @ 2015-03-26 20:39 人生不酱油 阅读(117) 评论(0) 推荐(0)