上一页 1 2 3 4 5 6 7 8 9 10 ··· 20 下一页
摘要: int longestConsecutive(vector &num) { // Note: The Solution object is instantiated only once and is reused by each test case. if(num.empty()) return 0; map m; int max_len = 1; for(int i=0;i0) continue; m[num[i]] = 1; ... 阅读全文
posted @ 2013-10-10 14:33 summer_zhou 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 直接模拟即可,就是int转string麻烦一点 string countAndSay(int n) { // Note: The Solution object is instantiated only once and is reused by each test case. //just do it straight; string res = "1"; if(n>s; res+=s; res+=prev.substr(j-1,1); ... 阅读全文
posted @ 2013-10-09 17:01 summer_zhou 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 使用优先级队列struct cmp{ bool operator() ( ListNode* a, ListNode* b ){ return a->val>b->val; }};class Solution {public: ListNode *mergeKLists(vector &lists) { // Note: The Solution object is instaentiated only once and is reused by each test case. int k = lists.size(); ... 阅读全文
posted @ 2013-10-09 16:47 summer_zhou 阅读(136) 评论(0) 推荐(0) 编辑
摘要: string longestCommonPrefix(vector &strs) { // Note: The Solution object is instantiated only once and is reused by each test case. if(strs.empty()) return ""; int last = strs[0].size(); for(int i=1;i<strs.size();i++) { last = min(last,(int... 阅读全文
posted @ 2013-10-09 15:00 summer_zhou 阅读(145) 评论(0) 推荐(0) 编辑
摘要: void merge(int A[], int m, int B[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int i = m-1; int j = n-1; int cur = m+n-1; while(i>=0&&j>=0) { if(A[i]>=B[j]) A[cur--] = A[i--]... 阅读全文
posted @ 2013-10-09 14:20 summer_zhou 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 二分 vector searchRange(int A[], int n, int target) { // Note: The Solution object is instantiated only once and is reused by each test case vector res(2,-1); int firstpos = findFirstPos(A,0,n-1,target); if(firstpos!=-1){ int lastpos = findLastPos(A,0,n-1,targ... 阅读全文
posted @ 2013-10-08 23:01 summer_zhou 阅读(143) 评论(0) 推荐(0) 编辑
摘要: vector insert(vector &intervals, Interval newInterval) { // Note: The Solution object is instantiated only once and is reused by each test case. vector res; int i = 0; int n = intervals.size(); while(i<n&&intervals[i].end<newInterval.start) { ... 阅读全文
posted @ 2013-10-08 22:33 summer_zhou 阅读(142) 评论(0) 推荐(0) 编辑
摘要: vector merge(vector &intervals) { // Note: The Solution object is instantiated only once and is reused by each test case. vector res; if(intervals.empty()) return res; sort(intervals.begin(),intervals.end(),cmp); res.push_back(intervals[0]); f... 阅读全文
posted @ 2013-10-08 22:16 summer_zhou 阅读(151) 评论(0) 推荐(0) 编辑
摘要: int m = 0,n=0; void solve(vector> &board) { // Start typing your C/C++ solution below // DO NOT write int main() function if(board.empty()||board[0].empty()) return; m = board.size(); n = board[0].size(); int i,j; for(j=0;j>&... 阅读全文
posted @ 2013-10-08 20:55 summer_zhou 阅读(141) 评论(0) 推荐(0) 编辑
摘要: DP + 回溯 vector> partition(string s) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; if(s.empty()) return res; int n = s.size(); vector> isPalin(n,vector(n,false)); int i,j; for(i=0;i... 阅读全文
posted @ 2013-10-08 20:49 summer_zhou 阅读(96) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 20 下一页