- 博客(60)
- 资源 (1)
- 收藏
- 关注
原创 [Leetcode]920. Number of Music Playlists
这个题目时动态规划里面比较hard的题目,解题思路:令数组dp[i][j]表示听i首歌中有j个不同的歌的方法数,所以最终的解为dp[L][N],dp[i][j]的状态转移方程分成两种情况讨论: 1.新加一首歌时新歌,对应的方法数为dp[i-1][j-1]*(N - (j-1));2.新加的一首歌是旧歌,同时j的大小打于K,对应的方法数为 dp[i-1][j]*(j-k)通过以上状态...
2018-12-14 17:40:11
244
1
原创 Cuda C权威指南学习笔记(二)
文章目录复习线程管理编写核函数复习CUDA的抽象层次:内存结构,线程结构,障碍同步。线程管理CUDA线程管理是通过一个两层的线程层次结构完成的,也就是网格和线程块。通过以下代码可以看到这个结构是如何运行的#include<cuda_runtime.h>#include<stdio.h>#include<iostream>using names...
2018-12-07 20:44:26
263
原创 Cuda C权威指南学习笔记(一)
本次目录Hello world 例程Hello world 例程编译第一个hello文件, 首先创建hello.cu#include<iostream>using namespace std;int main(){ cout<<"Hello world"<<endl;}执行nvcc hello.cu -o hello, ./hello得到n...
2018-12-07 19:41:13
414
原创 [Leetcode]208. Implement Trie (Prefix Tree)
基础题,生成一个Trie树 struct NODE{ int val; NODE * next[26]; NODE(){ val = 0; for(int i = 0;i < 26;++i){ next[i] = nullptr; } }};const int maxn = ...
2018-12-06 15:26:43
140
原创 [Leetcode]215. Kth Largest Element in an Array
暴力解,复杂度是快排复杂度o(nlogn),空间是o(1) class Solution {public: int findKthLargest(vector<int>& nums, int k) { sort(nums.begin(),nums.end(),greater<int>()); return nums[k...
2018-12-06 14:36:50
142
原创 [Leetcode] 120. Triangle
class Solution {public: int minimumTotal(vector<vector<int>>& triangle) { for(int i = 1; i < triangle.size(); ++i){ for(int j = 0; j < triangle[i].size(...
2018-12-05 19:48:27
137
原创 [Leetcode]115. Distinct Subsequences
第一个递归版本,会TLE,很简单,不用几行class Solution {public: int numDistinct(string s, string t) { if(s.size() < t.size() ) return 0; if(s == t) return 1; if(s[0] == t[0]){ ...
2018-12-05 18:04:00
121
原创 [Leetcode]87. Scramble String
class Solution {public: bool isScramble(string s1, string s2) { if(s1.size() != s2.size()) return false; if(s1 == s2) return true; int check[26] = {0}; for(int i ...
2018-12-05 16:28:40
117
原创 [leetcode]207. Course Schedule
第一种图的方法:超时struct Edge{ int to; Edge(int x){ to = x; }};struct Node{ vector<Edge> edges; int indegree; Node(){ indegree=0; }};struct Graph{ ...
2018-12-03 15:27:30
136
原创 [Leetcode]231. Power of Two
关键函数lowbit:x&(-x) class Solution {public: bool isPowerOfTwo(int n) { long long t = n; if(t == 0) return false; return (t & (-t)) == t; }}; ...
2018-12-03 13:57:40
143
原创 [Leetcode]72. Edit Distance
编辑距离:两个字符串s,t,s变到t的最短距离,包含3个操作添加、删除以及修改令dp[i][j]表示s的前i个(含i)字符变到t的前j个字符的最短操作于是有两种情况1.s[i] == t[j]此时 dp[i][j] = min(min(dp[i-1][j-1], //表示不做修改 dp[i][j-1]+1), //表示前i个字符...
2018-12-01 15:17:48
118
原创 [Leetcode]86. Partition List
这个题的关键在于读懂题意:就是把小于val的点移动到链表中大于等于val的第一个点的右边,同时不改变它们的相对顺序 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), ne...
2018-11-30 14:41:15
127
原创 [Leetcode]167. Two Sum II - Input array is sorted
class Solution {public: vector<int> twoSum(vector<int>& numbers, int target) { vector<int> ans;//{numbers[i],numbers[mid]}; for(int i =...
2018-11-29 13:59:03
114
原创 [Leetcode]141. Linked List Cycle
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasCyc...
2018-11-29 13:43:30
110
原创 [Leetcode]95. Unique Binary Search Trees II
题目的意思是输出所有可能的二叉树 坑点:1.注意返回的数据类型,vector<TreeNode*>是一个头节点,所以每回插入都要new,否则会改变上一个插入的节点2.多练习树的递归算法,很有用3.使用类似于STL的迭代方式时要注意左闭右开的原则/** * Definition for a binary tree node. * struct TreeNode {...
2018-11-29 13:34:52
119
原创 __stdcall 与cdecl的不同
stdcall参数从右向左压入堆栈函数被调用者修改堆栈函数名(在编译器这个层次)自动加前导的下划线,后面紧跟一个@符号,其后紧跟着参数的尺寸在win32应用程序里,宏APIENTRY,WINAPI,都表示_stdcall,非常常见。cdeclcdecl 是C Declaration的缩写(declaration,声明),表示C语言默认的函数调用方法:所有参数从右到左依次入栈,这...
2018-11-28 18:28:36
128
原创 [Leetcode]根据中序排列和前序排列重建二叉树
中序和后序重建二叉树/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {}...
2018-11-27 10:39:19
392
原创 [Leetcode]80. Remove Duplicates from Sorted Array II
基本题class Solution {public: int removeDuplicates(vector<int>& nums) { int j = -1; int count = 0; for(int i = 0;i < nums.size();i++){ if(i != 0 ...
2018-11-27 10:34:33
106
原创 [Leetcode]125. Valid Palindrome
注意输入是数字的情况class Solution {public: bool isPalindrome(string s) { int l = 0; int r = s.size()-1; while(l < r){ while(l < r && !((s[l] >= 'A'...
2018-11-26 11:14:11
106
原创 [leetcode]
const int x=[]{ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return 0;}();class Solution { const int inf = 0x3f3f3f;public: int maxArea(vector<int>& height) { ...
2018-11-25 23:35:16
127
原创 [Leetcode] 232. Implement Queue using Stacks
class MyQueue {private : stack<int> sk1,sk2;public: /** Initialize your data structure here. */ MyQueue() { } /** Push element x to the back of queue. */ ...
2018-11-25 23:17:19
187
原创 [Leetcode ]225. Implement Stack using Queues
class MyStack {private: queue<int> q1;public: /** Initialize your data structure here. */ MyStack() { } /** Push element x onto stack. */ void push(int x...
2018-11-25 23:11:51
99
原创 [Leetcode]226. Invert Binary Tree
递归算法可解,就是逐层交换它们各自的子节点就行了。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), ...
2018-11-25 22:05:25
102
原创 WEBPACK笔记(一)
//初始化一个npm库,这一点比python好用很多npm init//安装各种依赖npm i webpack webpack-cli express element-ui //修改package.json//添加webpack.config.js,设置输入输出的位置npx webpack //输出目标 ...
2018-11-24 16:14:10
112
原创 [Leetcode]24. Swap Nodes in Pairs
这个题目中等难度,难点在于:1.奇数链表最后一个不会交换2.交换指针变量要用指针的指针才能真正交换正确的变量值/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), ne...
2018-11-24 15:38:32
88
原创 [leetcode]19. Remove Nth Node From End of List
这个题要注意的点:1.删除的是起始点2.删除的是最终的点/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class ...
2018-11-24 15:07:58
102
原创 [Leetcode]20. Valid Parentheses
简单题,一次过class Solution {public: bool isValid(string s) { stack<char> sk; for(auto c : s){ switch(c){ case '(': sk.push(c);...
2018-11-24 11:28:57
110
原创 [Leetcode]21. Merge Two Sorted Lists
合并两个排序好的列表,递归算法pass/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {pu...
2018-11-24 11:19:48
108
原创 [Leetcode]28. Implement strStr()
题目很简单,KMP算法搞定 class Solution {public: void prekmp(string s,int *next){ int j = -1; int n = s.size(); next[0] = -1; int i = 0; while(i < n-1){ ...
2018-11-24 01:45:29
100
原创 [Leetcode] 69. Sqrt(x)
这个题的问题在于二分搜索后的结果的平方一定要小于目标值,所以特殊情况下要减一class Solution {public: int mySqrt(int x) { int l = 0; int r = x; long mid = l + ((r - l) >> 1); while(l <= r){...
2018-11-22 20:11:14
94
原创 [Leetcode] 98. Validate Binary Search Tree
第一个思路,不正确,因为没有考虑左右子树上的不一致问题/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL)...
2018-11-22 19:55:36
104
原创 [Leetcode]567. Permutation in String
最开始的思路是求全排列,然后find一下:class Solution { void swap(char &a, char &b){ char c=a; a=b; b=c; } bool Permutation(string &s){ if(s.size()==0 ) return...
2018-11-22 11:58:17
133
原创 [Leetcode]27. Remove Element
使用库函数upper,lower可以很方便的找到对应的位置删去就好了坑点:1.空数组2.删去的值有可能不在数组里面 const int x=[]{ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return 0;}();class Solution {public: int ...
2018-11-22 10:46:00
101
原创 [Leetcode]33. Search in Rotated Sorted Array
思路很简单,分类讨论:如果要查找的数小于数组第一个数,那就在旋转后的后半数组如果要查找的数大于数组第一个数,那就在前半数组找坑点: 1.注意空输入 2.注意看是否有可能有重复的数存在,这个题是没有重复的数的//剑指offer上面有const int x=[]{ std::ios::sync_with_stdio(false); std::cin.tie(...
2018-11-21 22:14:43
90
转载 pip报错:is not a supported wheel on this platform
可能的原因1:安装的不是对应python版本的库,下载的库名中cp27代表python2.7,其它同理。可能的原因2:这个是我遇到的情况(下载的是对应版本的库,然后仍然提示不支持当前平台) 我下载到的numpy库文件名: numpy-1.10.4+mkl-cp27-cp27m-win32.whl 使用pip安装(在命令行中):pip install numpy...
2018-11-18 15:25:27
555
原创 [Leetcode] 3Sum Closest
const int inf = 0x3f3f3f;const int x = []{ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return 0;}();class Solution {public: int threeSumClosest(vector<int>&a...
2018-11-18 13:57:42
108
原创 APT建立本地源
APT建立本地源实验室提供的集群因为安全原因无法联网,亦无法在联网条件下安装好环境后断网使用,这样也很不方便,于是考虑其它方法安装。该集群要安装的软件有:nvidia驱动cudacudnnpythonflask。。。。由于是裸机安装,寻找这些安装包及其依赖要有大量的精力,所以决定使用硬盘批量下载清华apt源,如何同步到集群上面完成整个环境的安装。1.首先建立文件mirror....
2018-11-18 13:37:57
1018
原创 [Leetcode] 66. Plus One
这个题很简单,实现一个加法器,唯一有用的地方是第一位进位的话要插入一个1const int x = []{ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return 0;}();class Solution {public: vector<int> plusOne(vect...
2018-11-17 10:56:50
102
原创 [Leetcode]64. Minimum Path Sum
优先队列图搜索方法,超时,查看discussion发现是因为动态规划比这个快。。 = =可能因为优先队列是一棵红黑树要插入的缘故吧。下面是优先队列的方法。const int x=[]{ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return 0;}();//这里有个链表记录它的前驱节点...
2018-11-14 11:38:04
116
原创 [Leetcode] 92. Reverse Linked List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */const static int x=[]{ std::ios::syn...
2018-11-14 09:41:07
112
opengl软件包
2018-06-04
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人