算法
文章平均质量分 63
Elinx
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 274 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 · 368 阅读 · 0 评论 -
枚举/组合
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
[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 阅读 · 0 评论 -
[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 阅读 · 0 评论 -
[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 阅读 · 0 评论 -
[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 · 470 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 · 2004 阅读 · 1 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 · 699 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 · 258 阅读 · 0 评论
分享