![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
c0d3喵
这个作者很懒,什么都没留下…
展开
-
【LeetCode笔记】Wildcard Matching 和 Regular Expression Matching
这两道题第一眼看上去都差不多,通常思路就是用动态规划做。对于Regular Expression Matching可以50ms通过所有test case; 而对于Wildcard Matching却需要900ms.不知道OJ用了什么不同的test case,但是DP的时间复杂度是M*N的,没道理差别这么大。Dissuss里很多人用DP还不能通过。原因可能如下:boo原创 2014-12-22 12:12:01 · 1374 阅读 · 0 评论 -
【LeetCode笔记】Compare Version Numbers
int compareVersion(string version1, string version2) {stringstream s1(version1), s2(version2);while(1){int i1= 0, i2 = 0;if(getline(s1, version1, '.')) //if读取成功,将字符串convert为整型i1 = stoi(ver原创 2015-03-09 05:43:25 · 660 阅读 · 0 评论 -
【LeetCode笔记】Linked List Cycle
Set a fast runner and a slow runner. The fast runner jumps 2 nodes at one time, and the slow runner jumps 1 nodes at one time.原创 2014-07-10 03:44:13 · 534 阅读 · 0 评论 -
【LeetCode笔记】Word Break
Bottom up DPclass Solution {public: bool wordBreak(string s, unordered_setstring> &dict) { int len = s.length(); vectorbool> dp(len + 1,false); dp[len] = true;转载 2014-08-26 06:19:17 · 516 阅读 · 0 评论 -
【LeetCode笔记】Regular Expression Matching
Recursive method:bool isMatch(const char *s, const char *p) { //p is empty if(*p == '\0') return (*s == '\0'); //p is not empty //a * is followed if(*(p + 1) == '*'){ //take 0 preceding原创 2014-10-06 09:30:19 · 576 阅读 · 0 评论 -
【LeetCode笔记】Merge Intervals
用STL sort重写Compare时发生了一个错误,以前没有注意到的。我第一次写的:struct MyCmp{bool operator()(const Interval a, const Interval b){return (a.start }}mycmp;在运行是得到了Runtime Error。后来把 简单测试了一下:Input:(50,60)原创 2014-11-30 09:09:13 · 519 阅读 · 0 评论 -
【LeetCode笔记】String to Integer (atoi)
用了几个Character handling functions,简化了代码。挺实用的。 (ctype.h)Character handling functionsThis header declares a set of functions to classify and transform individual characters.FunctionsThese fun原创 2015-02-13 12:57:46 · 456 阅读 · 0 评论 -
【LeetCode笔记】Candy
Something wrong with my solution as describing below.I got a wrong answer: Input: [1,2,4,4,3] Output: 10 Expected: 9my output is 1+2+3+3+1 = 10. and I think OJ's is 1+2+3+2+1 = 9how can原创 2014-08-28 14:40:25 · 619 阅读 · 0 评论 -
【LeetCode笔记】Reverse Integer
1. If want to reuse the same stringstream object, need to clear the buffer before use.原创 2014-07-08 23:44:29 · 506 阅读 · 0 评论 -
【LeetCode笔记】Palindrome Partitioning
2 DP methods are used in this implementation:1. DP method to find all palind原创 2014-10-04 07:48:23 · 466 阅读 · 0 评论 -
【LeetCode笔记】Longest Palindromic Substring
Implement the Manacher’s algorithm原创 2014-10-01 06:54:17 · 561 阅读 · 0 评论 -
【LeetCode笔记】Best Time to Buy and Sell Stock II
这个笔记跟这个题目没有多大关系。原创 2014-10-09 11:54:56 · 494 阅读 · 0 评论 -
【LeetCode笔记】Rotate Array
写了两种方法1. 用STL函数void rotate(int num[], int n, int k){ k %= n; if(k == 0) return; reverse(num, num + n); reverse(num, num + k); //[0..k-1] reverse(num + k, num +原创 2015-03-10 09:38:35 · 523 阅读 · 0 评论