随笔分类 -  Algorithm

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 16 下一页
classic algorithm, problem
摘要:1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 class Solution { 9 public: 10 double findMedianSortedArra... 阅读全文
posted @ 2014-09-19 19:04 卖程序的小歪 阅读(316) 评论(0) 推荐(0)
摘要:class Solution {private: int shd_cnt[256]; int cur_cnt[256];public: string minWindow(string S, string T) { int slen = S.length(); ... 阅读全文
posted @ 2014-09-16 20:54 卖程序的小歪 阅读(165) 评论(0) 推荐(0)
摘要:记忆搜索总是一个快速的方法(这里假设测试用例中s1和s2的长度都不超过(2^16) - 1), 当然用记忆搜索的,往往就可以写成DP的形式的,不用担心大数据时栈溢出了#include #include #include #include #include using namespace std;cl... 阅读全文
posted @ 2014-09-16 18:50 卖程序的小歪 阅读(214) 评论(0) 推荐(0)
摘要:class Solution {#define SINGLE 1#define MULTIP 2public: bool isMatch(const char *s, const char *p) { if (s == NULL || p == NULL) return true... 阅读全文
posted @ 2014-09-14 00:27 卖程序的小歪 阅读(209) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 10 using namespace std; 11 12 typedef pa... 阅读全文
posted @ 2014-09-13 02:47 卖程序的小歪 阅读(247) 评论(0) 推荐(0)
摘要:室友在做于是也做一发,跟已知两种遍历序列还原二叉树的思路类似,感觉PAT上的题目跟书本知识靠的近一些#include #include #include using namespace std;void print_data(const vector &as, const vector &ns) {... 阅读全文
posted @ 2014-09-12 00:10 卖程序的小歪 阅读(257) 评论(0) 推荐(0)
摘要:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa... 阅读全文
posted @ 2014-09-11 00:31 卖程序的小歪 阅读(259) 评论(0) 推荐(0)
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文
posted @ 2014-08-25 00:32 卖程序的小歪 阅读(132) 评论(0) 推荐(0)
摘要:1 #include 2 3 int main() { 4 long n, a, b, c; 5 long i; 6 int ga, gb, gc, r; 7 scanf("%ld", &n); 8 for (i=... 阅读全文
posted @ 2014-08-20 23:46 卖程序的小歪 阅读(210) 评论(0) 推荐(0)
摘要:1 #include 2 3 void print(int *a, int start , int end); 4 5 void quick_sort(int *a, int start, int end) { 6 if (start + 1 >= end) return; 7 ... 阅读全文
posted @ 2014-08-19 18:17 卖程序的小歪 阅读(151) 评论(0) 推荐(0)
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文
posted @ 2014-08-17 20:05 卖程序的小歪 阅读(154) 评论(0) 推荐(0)
摘要:class Solution {public: int longestValidParentheses(string s) { vector stack; int maxlen = 0; int curlen = 0; int last ... 阅读全文
posted @ 2014-08-12 10:18 卖程序的小歪 阅读(154) 评论(0) 推荐(0)
摘要:class Solution {public: ListNode *reverseKGroup(ListNode *head, int k) { if (k next = rhead; } last = rtail; } ... 阅读全文
posted @ 2014-07-27 23:18 卖程序的小歪 阅读(230) 评论(0) 推荐(0)
摘要:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni... 阅读全文
posted @ 2014-07-27 21:59 卖程序的小歪 阅读(192) 评论(0) 推荐(0)
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and ... 阅读全文
posted @ 2014-07-27 13:26 卖程序的小歪 阅读(167) 评论(0) 推荐(0)
摘要:struct mystat { int idx; int cnt[26]; mystat(int id = 0) {idx = id;}};bool cmp(const mystat &a, const mystat &b) { for (int i=0; i b.cnt[i... 阅读全文
posted @ 2014-07-27 12:42 卖程序的小歪 阅读(112) 评论(0) 推荐(0)
摘要:class Solution {public: bool isMatch(const char *s, const char *p) { if (s == NULL || p == NULL) return false; int slen = 0; i... 阅读全文
posted @ 2014-07-26 23:43 卖程序的小歪 阅读(225) 评论(0) 推荐(0)
摘要:class Solution {public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) { UndirectedGraphNode *clone = dfs(node); dfs_clea... 阅读全文
posted @ 2014-07-22 20:29 卖程序的小歪 阅读(182) 评论(0) 推荐(0)
摘要:class Solution {public: int maxProfit(vector &prices) { int len = prices.size(); if (len i2r(len, 0); vector i2l(len, 0); ... 阅读全文
posted @ 2014-07-22 16:09 卖程序的小歪 阅读(169) 评论(0) 推荐(0)
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文
posted @ 2014-07-22 10:56 卖程序的小歪 阅读(141) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 16 下一页