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 ...
分类:
其他好文 时间:
2015-03-20 09:11:55
阅读次数:
143
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) { ...
分类:
其他好文 时间:
2015-03-20 09:09:30
阅读次数:
101
Just use two pointers. CC150 classical question 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNo...
分类:
其他好文 时间:
2015-03-20 08:06:22
阅读次数:
125
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...
分类:
其他好文 时间:
2015-03-20 08:06:07
阅读次数:
164
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()...
分类:
其他好文 时间:
2015-03-20 08:06:00
阅读次数:
121
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...
分类:
其他好文 时间:
2015-03-20 08:05:24
阅读次数:
123
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne...
分类:
其他好文 时间:
2015-03-20 08:03:53
阅读次数:
125
Tried it with spliting words method. But need to check empty situation. 1 class Solution { 2 public: 3 int lengthOfLastWord(const char *s) { 4 ...
分类:
其他好文 时间:
2015-03-20 08:03:07
阅读次数:
129
It use the hashset to do the tricks. 1 class Solution { 2 public: 3 int longestConsecutive(vector &num) { 4 int len = num.size(), result =...
分类:
其他好文 时间:
2015-03-20 08:02:46
阅读次数:
146
Use two vector to record left and right indexes that can extend the blocks. 1 class Solution { 2 public: 3 int largestRectangleArea(vector &height...
分类:
其他好文 时间:
2015-03-20 08:02:31
阅读次数:
126