摘要:
Notes:1. Do not forget to check xi == xj. It will cause INF.2. DO not forget to initialize the iterator. 1 /** 2 * Definition for a point. 3 * struc... 阅读全文
posted @ 2015-03-20 09:00
keepshuatishuati
阅读(160)
评论(0)
推荐(0)
摘要:
1. Use memory :In the question, it already stated that there must be a majority element. So discard empty situation.Also it needs the number, not the ... 阅读全文
posted @ 2015-03-20 08:37
keepshuatishuati
阅读(160)
评论(0)
推荐(0)
摘要:
1 struct Node { 2 int key, value; 3 Node(int k, int v) : key(k), value(v) {} 4 }; 5 6 class LRUCache{ 7 private: 8 int size; 9 list ... 阅读全文
posted @ 2015-03-20 08:17
keepshuatishuati
阅读(117)
评论(0)
推荐(0)
摘要:
Notes:Do not forget to clean the total and rec. 1 class Solution { 2 public: 3 int longestValidParentheses(string s) { 4 int len = s.size(... 阅读全文
posted @ 2015-03-20 08:09
keepshuatishuati
阅读(115)
评论(0)
推荐(0)
摘要:
For this problem, we are OK to use hash set, since no numbers are needed. 1 class Solution { 2 public: 3 int lengthOfLongestSubstring(string s) { ... 阅读全文
posted @ 2015-03-20 07:58
keepshuatishuati
阅读(127)
评论(0)
推荐(0)
摘要:
At first beginning, I was trying to use hash set to record the characters. But I found that was wrong.Because if there are couple same chars, when you... 阅读全文
posted @ 2015-03-20 07:52
keepshuatishuati
阅读(134)
评论(0)
推荐(0)
摘要:
O(n2): 1 class Solution { 2 public: 3 string getP(string s, int start, int end) { 4 while (start >= 0 && end result.size()) result = s1;1... 阅读全文
posted @ 2015-03-20 07:33
keepshuatishuati
阅读(111)
评论(0)
推荐(0)
摘要:
It use the hashset to do the tricks. 1 class Solution { 2 public: 3 int longestConsecutive(vector &num) { 4 int len = num.size(), result =... 阅读全文
posted @ 2015-03-20 07:25
keepshuatishuati
阅读(134)
评论(0)
推荐(0)
摘要:
Seach one by one. 1 class Solution { 2 public: 3 string getNext(const string& s1, const string& s2) { 4 int len = min(s1.size(), s2.size()... 阅读全文
posted @ 2015-03-20 07:22
keepshuatishuati
阅读(135)
评论(0)
推荐(0)
摘要:
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne... 阅读全文
posted @ 2015-03-20 07:18
keepshuatishuati
阅读(136)
评论(0)
推荐(0)
摘要:
Just use two pointers. CC150 classical question 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNo... 阅读全文
posted @ 2015-03-20 07:16
keepshuatishuati
阅读(137)
评论(0)
推荐(0)
摘要:
This is just a combination. Use hashtable to hold the number ==> charsnotes:1. check corner case : input is empty, do not return vector contains empty... 阅读全文
posted @ 2015-03-20 07:13
keepshuatishuati
阅读(174)
评论(0)
推荐(0)
摘要:
Tried it with spliting words method. But need to check empty situation. 1 class Solution { 2 public: 3 int lengthOfLastWord(const char *s) { 4 ... 阅读全文
posted @ 2015-03-20 07:03
keepshuatishuati
阅读(142)
评论(0)
推荐(0)
摘要:
Use two vector to record left and right indexes that can extend the blocks. 1 class Solution { 2 public: 3 int largestRectangleArea(vector &height... 阅读全文
posted @ 2015-03-20 06:54
keepshuatishuati
阅读(120)
评论(0)
推荐(0)
摘要:
Corner case: when all the elements are 0. It should return "0", not "00000000".It use string to compare all the numbers. 1 class Solution { 2 public: ... 阅读全文
posted @ 2015-03-20 06:09
keepshuatishuati
阅读(130)
评论(0)
推荐(0)
摘要:
Same with Jump Game I. Just need a step parameter and assume there is no "0" value in the array. 1 class Solution { 2 public: 3 int jump(int A[], ... 阅读全文
posted @ 2015-03-20 05:54
keepshuatishuati
阅读(158)
评论(0)
推荐(0)
摘要:
Need a corner case check for only one element [0]. 1 class Solution { 2 public: 3 bool canJump(int A[], int n) { 4 if (n = n-1) return tru... 阅读全文
posted @ 2015-03-20 05:51
keepshuatishuati
阅读(130)
评论(0)
推荐(0)
摘要:
Find the common length part, then check with two pointers. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 *... 阅读全文
posted @ 2015-03-20 05:47
keepshuatishuati
阅读(141)
评论(0)
推荐(0)
摘要:
Notes:1. Even s3 is empty string, if s1 and s2 are emtpy, then it should be true.2. Do not mess up the size of label. 1 class Solution { 2 public: 3 ... 阅读全文
posted @ 2015-03-20 04:56
keepshuatishuati
阅读(120)
评论(0)
推荐(0)
摘要:
Pretty straight forward. 1 class Solution { 2 public: 3 string getRoman(int n, char ten, char five, char one) { 4 string result; 5 ... 阅读全文
posted @ 2015-03-20 04:11
keepshuatishuati
阅读(132)
评论(0)
推荐(0)
摘要:
Do not forget to break the inner loop, when you find the insert position. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * ... 阅读全文
posted @ 2015-03-20 04:07
keepshuatishuati
阅读(134)
评论(0)
推荐(0)
摘要:
Similar to merge intervals. But this is easier than merge interval, because every side is kind of "sorted". 1 /** 2 * Definition for an interval. 3 ... 阅读全文
posted @ 2015-03-20 03:07
keepshuatishuati
阅读(147)
评论(0)
推荐(0)
浙公网安备 33010602011771号