- 博客(17)
- 资源 (5)
- 收藏
- 关注
原创 LintCode Linked List专辑
1. Reverse Linked List 2. Remove Duplicates from Sorted List 3. Remove Duplicates from Sorted List II 4. Reverse Linked List II 5. Majority Number III 6. Partition List 7. 1. Reverse Li...
2018-05-05 22:31:16
437
原创 LintCode二分查找专辑
1. First Position of Target class Solution { public: /** * @param nums: The integer array. * @param target: Target to find. * @return: The first position of target. Position star...
2018-04-13 21:37:00
367
原创 枚举/组合
subsets description class Solution { public: /** * @param nums: A set of numbers * @return: A list of lists */ vector<vector<int>> subsets(vector<int> &a...
2018-04-07 12:33:23
407
原创 [DP] LeetCode Regular Expression Matching
algorithm procedure if the current text character is matching with the pattern character, which means the last character matched, then the result depends on the previous status: res(r,c)=res(r−1,c−1
2018-01-04 23:00:44
275
原创 LeetCode 2Sum, 3Sum, 4Sum
two sum problemthree accepted solutions are provided here with decreased time complexity.class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> res; #if 0
2018-01-03 22:29:41
272
原创 LeetCode 8-9 Solutions
8. String to Integer(atoi)class Solution { public: bool isDigit(char c) { return c >= '0' and c <='9'; } int myAtoi(string str) { size_t idx = 0; size_t len = str.length();
2018-01-01 21:55:12
257
原创 [DP] Hackerank The Coin Change Problem
You can find the problem description here, Sample Input 110 4 2 5 3 6Sample Output 15This is a typical knapsack problem with repetitions which can be easily solved by making a transaction table from to
2017-12-31 11:58:34
469
原创 Dynamic Programming part 1 -- Knapsack Problem
This article is adapted from this pdf. During a robbery, a burglar finds much more loot than he had expected and has to decide what to take. His bag (or “knapsack”) will hold a total weight of at most
2017-12-30 12:09:20
680
原创 [DP] LeetCode 5 Longest Palindromic Substring
O(N2)O(N^2) codeclass Solution { public: string longestPalindrome(string str) { int size = str.length(); int ps = 0, maxLen = 1; vector<vector<bool>> isP(size, vector<bool>(
2017-12-30 10:36:17
245
原创 [DP] Leetcode 300 Longest Increasing Subsequence
O(N2)O(N^2) codeclass Solution { public: int lengthOfLIS(vector<int>& seq) { if (seq.empty()) return 0; // lens indicate the sequence END by element t vector<int> lens(seq.s
2017-12-30 10:24:38
315
原创 1.3.1 FatMouse trade
WA: #include #include #include using namespace std; class Node { public: double ratio, mount,value; Node(double r,double m,double v){ ratio=r; mount=m; value=v; } bool operator>(const
2013-04-02 22:38:47
735
原创 1.2.8 Lowest Bit
#include #include #include using namespace std; int main(int argc, char* argv[]) { int get, count; while(cin >> get) { if(get == 0) return 1; bitset bs(get); count = 0; int len = bs
2013-04-02 21:10:47
698
原创 1.2.7 GPA
#include #include #include using namespace std; #define max 1000 int main(int argc, char* argv[]) { double result; int i; char line[max]; l: while(cin.getline(line, max)) { int len = string(
2013-04-01 21:53:26
1040
原创 Huffman树
要解决的问题是关于霍夫曼树的,题目在: http://acm.hdu.edu.cn/showproblem.php?pid=1053 直接写代码吧,不得不说写得真的很复杂,调试了半天,出了好多错哈: #include #include #include #include using namespace std; const int R = 27; // A~Z, _ cons
2013-01-18 15:40:27
736
原创 PQ使用
priority_queue默认用 priority。 第一次代码比较复杂: pq.cpp #include #include using namespace std; class NODE { public: char ch; int freq; bool operator>(const NODE n1) const
2013-01-17 16:42:10
2003
原创 DFS走迷宫
BFS走出的是一条最短路径,DFS走出的不一定是最短路径。只要把前面的BFS代码稍作修改,改成递归的形式即可。BFS使用的队列的数据结构来存储中间结果,DFS使用的是栈,因此DFS使用递归的形式。 #include #include #include #include #define MAXLEN 100 int edge_to[MAXLEN]; int maze[MAXLEN][MA
2013-01-04 14:05:35
1106
原创 BFS走迷宫
简单的走迷宫的算法,BFS就是把当前的顶点的邻接顶点都入队列,然后队列首端出队列,重复,知道所有的通路,然后一个一个的往回找即可。#include #include #include #include #define MAXLEN 100 int edge_to[MAXLEN]; int maze[MAXLEN][MAXLEN]; bool visited[MAXLEN][MAXLEN];
2013-01-04 10:52:49
960
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅