9 Elinx




TA的排名 26w+

LintCode Linked List专辑

1. Reverse Linked List2. Remove Duplicates from Sorted List3. Remove Duplicates from Sorted List II4. Reverse Linked List II5. Majority Number III6. Partition List7.1. Reverse Li...

2018-05-05 22:31:16


1. First Position of Targetclass 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


subsets descriptionclass 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

[DP] LeetCode Regular Expression Matching

algorithm procedureif 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

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

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

[DP] Hackerank The Coin Change Problem

You can find the problem description here, Sample Input 110 42 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

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

[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

[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

1.3.1 FatMouse trade

WA:#include#include#includeusing 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

1.2.8 Lowest Bit

#include#include#includeusing 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

1.2.7 GPA

#include#include#includeusing namespace std;#define max 1000int 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


要解决的问题是关于霍夫曼树的,题目在:http://acm.hdu.edu.cn/showproblem.php?pid=1053直接写代码吧,不得不说写得真的很复杂,调试了半天,出了好多错哈:#include#include#include#includeusing namespace std;const int R = 27; // A~Z, _cons

2013-01-18 15:40:27


priority_queue默认用 priority。第一次代码比较复杂:pq.cpp#include#includeusing namespace std;class NODE { public: char ch; int freq; bool operator>(const NODE n1) const

2013-01-17 16:42:10


BFS走出的是一条最短路径,DFS走出的不一定是最短路径。只要把前面的BFS代码稍作修改,改成递归的形式即可。BFS使用的队列的数据结构来存储中间结果,DFS使用的是栈,因此DFS使用递归的形式。#include#include#include#include#define MAXLEN 100int edge_to[MAXLEN];int maze[MAXLEN][MA

2013-01-04 14:05:35


简单的走迷宫的算法,BFS就是把当前的顶点的邻接顶点都入队列,然后队列首端出队列,重复,知道所有的通路,然后一个一个的往回找即可。#include#include#include#include#define MAXLEN 100int edge_to[MAXLEN];int maze[MAXLEN][MAXLEN];bool visited[MAXLEN][MAXLEN];

2013-01-04 10:52:49
勋章 我的勋章