随笔分类 - Algorithm
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...
阅读全文
摘要:class Solution {private: int shd_cnt[256]; int cur_cnt[256];public: string minWindow(string S, string T) { int slen = S.length(); ...
阅读全文
摘要:记忆搜索总是一个快速的方法(这里假设测试用例中s1和s2的长度都不超过(2^16) - 1), 当然用记忆搜索的,往往就可以写成DP的形式的,不用担心大数据时栈溢出了#include #include #include #include #include using namespace std;cl...
阅读全文
摘要:class Solution {#define SINGLE 1#define MULTIP 2public: bool isMatch(const char *s, const char *p) { if (s == NULL || p == NULL) return true...
阅读全文
摘要: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...
阅读全文
摘要:室友在做于是也做一发,跟已知两种遍历序列还原二叉树的思路类似,感觉PAT上的题目跟书本知识靠的近一些#include #include #include using namespace std;void print_data(const vector &as, const vector &ns) {...
阅读全文
摘要: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...
阅读全文
摘要: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 ...
阅读全文
摘要: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=...
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要:class Solution {public: int longestValidParentheses(string s) { vector stack; int maxlen = 0; int curlen = 0; int last ...
阅读全文
摘要:class Solution {public: ListNode *reverseKGroup(ListNode *head, int k) { if (k next = rhead; } last = rtail; } ...
阅读全文
摘要: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...
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要:class Solution {public: bool isMatch(const char *s, const char *p) { if (s == NULL || p == NULL) return false; int slen = 0; i...
阅读全文
摘要:class Solution {public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) { UndirectedGraphNode *clone = dfs(node); dfs_clea...
阅读全文
摘要:class Solution {public: int maxProfit(vector &prices) { int len = prices.size(); if (len i2r(len, 0); vector i2l(len, 0); ...
阅读全文
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express...
阅读全文

浙公网安备 33010602011771号