自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(67)
  • 收藏
  • 关注

转载 动态规划

搜索 贪心 分治 动态规划 记忆化搜索搜索:找遍所有解集空间得到最优解。贪心:每个阶段的最优解由上一阶段的最优解直接得到。分治:把每一个问题拆成互不重叠的子问题,分别解决。动态规划:能用动态规划解决的问题的性质:最优子结构:最优解包含的子问题的解也是最优的无后效性:子问题的最优解一旦确定就不会受到更大的问题的影响。重叠子问题Qu...

2019-03-05 11:09:00 73

转载 clickHeart.js

!function(e,t,a){ function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}...

2019-02-08 10:38:00 150

转载 LeetCode 31. Next Permutation

---恢复内容开始---生成下一个全排列数组。 1 class Solution { 2 public: 3 4 void reverse(vector<int>& p,int n){ 5 int temp,s=p.size(); 6 for (int i=n;i<(s+n)/2;i++){ 7 ...

2019-01-07 15:48:00 86

转载 LeetCode 29. Divide Two Integers

单纯减法不行,需要用到位运算。a<<b表示 a*(2^b).LeetCode出现了令人惊恐的同一段代码不同运行时间的情况.....class Solution {public: int divide(int x, int y) { int ans=0; if (x==INT_MIN && y==...

2018-09-15 00:22:00 71

转载 LeetCode 28. Implement strStr()

虽然分在EASY里面....模式匹配模板题。用KMP就行。void buildNext(string p,int next[]){ int pLen = p.length(); next[0] = -1; int t = -1; int j = 0; while (j < pLen - 1){ ...

2018-09-14 11:37:00 96

转载 LeetCode 27. Remove Element

class Solution {public: int removeElement(vector<int>& nums, int val) { int len=nums.size(),j=0; for (int i=0;i<len;i++){ if (nums[i]!=val) {...

2018-09-13 21:11:00 54

转载 Python笔记

一 安装环境二 变量  1. 变量不需要提前声明。字符串string 数字int/float 列表list转载于:https://www.cnblogs.com/travelller/p/9607562.html

2018-09-07 23:30:00 53

转载 使用 GitHub Pages+Hexo 搭建个人博客(mac)

一、环境配置1. brew下载 || 输入命令:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"2. git下载 || 输入命令:brew install git3. nodejs下载 ||...

2018-08-19 08:42:00 77

转载 LeetCode 26. Remove Duplicates from Sorted Array

很简单。class Solution {public: int removeDuplicates(vector<int>& a) { int n=a.size(); if (!n) return 0; int i=0,j=1; while(j<n){ ...

2018-08-14 17:17:00 48

转载 LeetCode 24. Swap Nodes in Pairs

考察链表操作。class Solution {public: ListNode* swapPairs(ListNode* head) { if (head==NULL) return NULL; if (head->next==NULL) return head; ListNode *preHead=new...

2018-08-12 22:54:00 61

转载 LeetCode 22. Generate Parentheses

这道题想不出来是因为没有抽象出他的数学模型——对于每一个位置,前面左括号的个数都大于等于右括号个数。class Solution {public: vector<string> generateParenthesis(int n) { vector<string> ans; generate(ans,n,n...

2018-08-12 18:32:00 55

转载 LeetCode 21. Merge Two Sorted Lists

链表并归排序/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {...

2018-08-12 11:39:00 61

转载 LeetCode 20. Valid Parentheses

栈的教科书式套路。class Solution {public: bool isValid(string s) { stack<char> a; int n=s.length(); for (int i=0;i<n;i++){ if (s[i]=='('||s[i]==...

2018-08-12 11:01:00 60

转载 LeetCode 19. Remove Nth Node From End of List

链表题。很简单但是debug了非常久。愚蠢如我...把所有地址存在数组里。空间复杂度.../** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next...

2018-08-12 10:35:00 63

转载 LeetCode 17. Letter Combinations of a Phone Number

暴搜。void DFS(int pos,string di,string temp,vector<string> &ans){ if (pos==0) {ans.push_back(temp);return;} string m[8] = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", ...

2018-08-09 23:28:00 50

转载 LeetCode 18. 4Sum

难点在于不能有重复。开始的思路是先两两求和,然后对得到的新序列求2Sum,但是很难排重。本想利用set<set<int>>排重,结果因为stl内部实现机制,应该是做不到。可行的思路是,外层暴力fix前两个数,内层一个循环固定后两个数。还是注意排重。class Solution {public: vector<vector&...

2018-08-09 22:12:00 61

转载 LeetCode 16. 3Sum Closest

类似上一题15 3Sumclass Solution {public: int threeSumClosest(vector<int>& nums, int target) { sort(nums.begin(),nums.end()); int len=nums.size(),l,r,min=INT_M...

2018-08-09 16:07:00 63

转载 LeetCode 15. 3Sum

求无序数列中三个数和为0的所有情况。思路:排序。外层循环fix第一个数O(n)。内层循环O(n)同时寻找第二个和第三个数和为第一个数的相反数:考虑到不能出现重复情况,所以内层循环每次从第一个数的下一个值进行循环;两个指针分别指向第一个数的下一个数,和序列的最后一个数,如果三个数之和大于0,右指针向左,反之左指针向右。注意:为避免出现重复,除序列中的首元素,如果当前fix的第...

2018-08-09 12:11:00 64

转载 LeetCode 14. Longest Common Prefix

简单题。纵向比较(每个字符串的第一个第二个...)和横向比较(两两字符串的最长公共前缀...)我对所有串进行排序,然后求最大和最小两个子串最长公共前缀。(不确定String compare如何实现,估计复杂度略高,但耗时都是4ms)int cmp(string a,string b) { return a.compare(b)<0; }...

2018-08-07 20:10:00 66

转载 LeetCode 13. Roman to Integer

很无聊的题。可以写成比较复杂的分支,但是discuss中有人把代码写的非常简洁,虽然我不喜欢这样使用unordered_map,但可以直接换成数组(只不过会浪费空间)。class Solution {public: int romanToInt(string s) { int c[26]={0}; c['I'-'A']=1;c...

2018-08-07 18:05:00 62

转载 LeetCode 12. Integer to Roman

很简单。直接打表。emm但是似乎大部分人认真找规律写的代码...class Solution {public: string intToRoman(int num) { int a[4]={0}; char s[4][10][6]={{"","I","II","III","IV","V","VI","VII","VIII","...

2018-08-07 15:49:00 49

转载 LeetCode 11. Container With Most Water

暴力O(n^2),但是可以通过一些“剪枝”使其达到O(n),但是证明是一个问题。We starts with the widest container, l = 0 and r = n - 1. Let's say the left one is shorter: h[l] < h[r]. Then, this is already the largest containe...

2018-08-07 14:49:00 43

转载 LeetCode 9. Palindrome Number

很简单。class Solution {public: bool isPalindrome(int x) { if(x<0) return false; if(x<10) return true; int i=1,j=0,a[20]={0}; while (x!=0){ ...

2018-08-07 13:37:00 47

转载 LeetCode 8. String to Integer (atoi)

很简单。class Solution {public: int myAtoi(string str) { int i=0,c=1;long long ans=0; while(str[i]==' ') i++; if((str[i]>'9'||str[i]<'0')&&(str[i]!...

2018-08-07 12:25:00 52

转载 LeetCode 7. Reverse Integer

很简单。不要忽略特殊情况x=INT_MIN处理(the 32-bit signed integer range: [−2^31, 2^31− 1])。class Solution {public: int reverse(int x) { if (x==INT_MIN) return 0; if (x<0) return...

2018-08-07 11:29:00 40

转载 LeetCode 6. ZigZag Conversion

很简单,不要忽略numRows=1的特殊情况处理。approach 1:按结果顺序直接计算每个位置的下标class Solution {public: string convert(string s, int numRows) { int a=0,b,x=2*numRows-2,p=0,len=s.length(); ...

2018-08-07 10:22:00 42

转载 LeetCode 5. Longest Palindromic Substring

求字符串的最长回文子串。看了hint没看solution。开心。暴力的思路是O(n^2) start - end pairs and O(n) palindromic checks。但是1000的复杂度只能采用O(n^2)的做法。所以目标是压缩cheak过程的复杂度。关键是:如何利用之前的判断结果?如:已知aba是回文,则xabax是回文,而xabay不是。但是因为复杂度,...

2018-08-06 23:39:00 54

转载 Todo list

1.RK hashKMPz algorithm http://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/2.POJ 2758转载于:https://www.cnblogs.com/travelller/p/9375710.html...

2018-07-27 09:34:00 73

转载 LeetCode 4. Median of two sorted arrays

求两个数组组成的数组的中位数。要求复杂度O(log(M+N)).思路:这个复杂度肯定要用二分,关键是怎么分。求两个数组的中位数相当于求两个数组的第k个值问题的特例。在后者问题上,我们设短数组为array1,长数组为array2,然后对array1设一个指针i,对array2设指针j,令j=k-i(固定短数组为array1是为了保证j不为负数),在0...m中对i进行二分取...

2018-06-08 13:54:00 50

转载 LeetCode 3. Longest Substring Without Repeating Characters

求一个字符串中无重复元素的最长子串。解法很多。总的来说,因为 java 封装了很多类,类内的函数也多,所以比C++更好实现。解法一:brute force O(n^3)  枚举每一个子串O(n^2),判断其中有没有重复元素(使用java中的hashset判断某元素是否在集合中O(1),判断子串中有无重复元素O(n),C++标准模板库中的 unordered_map 可以...

2018-06-01 23:52:00 71

转载 LeetCode 2. Add Two Numbers

把链表构成的两个数相加。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class S...

2018-06-01 15:24:00 46

转载 LeetCode 1. Two Sum

给定数组和一个值,求数组中两个数和为该值时,两个数的标号。结果单一,不能选取同一个数两次。Keywords: O(n); unordered_map; hash#include <unordered_map>#include <cstdio>using namespace std;class Solution {public:...

2018-05-31 17:30:00 42

转载 LeetCode 0. Preparation

诶...碰到LeetCode这种没有数据范围/input/output的OJ很尴尬了...一 Run C++ in Sublime Text 3 on MAC OSX:  0.官网下载 Sublime text 。MAC OS自带g++.(所以不用安装xcode/command line tools等)  1.点击Sublime菜单栏Tools->Build Sy...

2018-05-31 00:22:00 63

转载 Machine Learning——笔记一

1.In general, any machine learning problem can be assigned to one of two broad classifications:  Supervised learning and Unsupervised learning.2. DefinationSupervised learning : "right...

2018-04-21 07:21:00 50

转载 总结——DFS && BFS

深度优先搜索和广度优先搜索1. 思路  深度优先搜索伪代码:void dfs(状态A){ if (A不合法) return; if (A为目标状态) 输出; if (A不为目标状态) dfs(A+x);}  广度优先搜索伪代码:queue<int> Q;Q.push(head)whi...

2018-04-11 12:00:00 66

转载 总结——并查集

并查集(Union-find Sets)一 组成  并查集是一种用于处理一些不相交集合的合并问题的数据结构。主要由一个数组和两个函数组成。  数组:pre[] 用于记录每个点的前导节点。  函数:find() 查找根节点。路径压缩。int find(int x) {//递归 if (x != pre[x]) pre[x] = find(pre[x]);...

2018-04-10 22:52:00 63

转载 总结——常用函数

<cstring>  memset(a,0,sizeof(a));<algorithm>  sort(a,a+20);转载于:https://www.cnblogs.com/travelller/p/8776692.html

2018-04-10 09:55:00 41

转载 SDUT 1

A 2152 Phone Number:水    #include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;int cmp(string a,string b) { ...

2018-04-10 09:53:00 145

转载 总结——数论:快速幂

注意:依据题意就决定用int/long long1. 快速幂:求abint fastPow(int a,int b){ int ans=1,base=a; while(b){ if(b&1!=0)   ans*=base; base*=base; b>>=1;...

2018-03-27 11:59:00 63

转载 总结——数论:解高次同余方程 BSGS算法

解高次同余方程:已知 A B C(C为素数) , 求方程 Ax≡B(mod C) 的最小x值。1. 解范围分析:  由欧拉函数的性质可知,对于素数C,φ(C)=C-1。  又因 C 为素数,所以 (A,C)=1 , 由欧拉定理可知,Aφ(C)≡1(mod C).//或者直接由费马小定理可知,AC-1≡1(mod C)。  又因已知 A0=1 , 即 A0≡1(mod C)...

2018-03-24 13:18:00 484

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除