自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

庾信平生最萧瑟

除却君身三重雪,天下谁人配白衣

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

原创 如何做研究和读论文

如何做研究和写论文 - 周志华本文对网上的一些关于读论文的资源做出了一个汇总。研究过程:topic -> problem -> idea -> concrete导师给topic或者自己找topic阅读关于该话题的重要文献,了解该话题的研究历程、现状请导师推荐基于导师推荐的读物,顺藤摸瓜选择最适合自己的topic自己的兴趣自己的知识结构是否可以获得必要的资源问题导师给自己问题自己产生问题,导师帮自己判断IDEA是新的idea吗?是

2020-08-01 22:59:26 202 1

原创 LeetCode 797. 所有可能的路径

原题目:https://leetcode-cn.com/problems/all-paths-from-source-to-target/思路:使用BFS + 回溯算法代码:class Solution { vector<vector<int>> ans; vector<int> tmp; void bfs(vector<vector<int>>& graph,int index){ ..

2020-11-05 23:18:56 355

原创 LeetCode 1365. 有多少小于当前数字的数字

原题目:https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/思路:采用计数排序的方法代码:class Solution {public: vector<int> smallerNumbersThanCurrent(vector<int>& nums) { vector<int> cnt(10..

2020-10-26 18:30:07 220

原创 LeetCode 143. 重排链表

原题目:https://leetcode-cn.com/problems/reorder-list/思路:使用vector存储节点,然后使用双指针进行重新连接,最后注意最后的节点的next置为空代码:class Solution {public: void reorderList(ListNode *head) { if (head == nullptr) { return; } vector&l..

2020-10-20 12:47:47 227

原创 重定向 --- 同时在中断和文件进行输出

重定向 --- 同时在中断和文件进行输出使用重定向技术,在模型训练的过程中同时在中断和日志文件中输出我们的结果。代码:class Logger(object): def __init__(self, filename='default.log', stream=sys.stdout): self.terminal = stream self.log = open(filename, 'a') def write(self, message):..

2020-10-16 16:52:56 190

原创 LeetCode 977. 有序数组的平方

原题目:https://leetcode-cn.com/problems/squares-of-a-sorted-array/思路:使用双指针,从后向前加元素。代码:class Solution {public: vector<int> sortedSquares(vector<int>& A) { int i=0,j=A.size()-1,index = A.size()-1; vector<in..

2020-10-16 16:47:48 278

原创 LeetCode 116. 填充每个节点的下一个右侧节点指针

原题目:https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node/思路:采用BFS,使用size记录该层的个数,然后修改next指针就可以了代码class Solution {public: Node* connect(Node* root) { if(root == nullptr) return root; queue<Node*&..

2020-10-16 16:01:52 83

原创 LeetCode 1002. 查找常用字符

原题目:https://leetcode-cn.com/problems/find-common-characters/思路:使用哈希表,每次遍历完一个字符串后,取最小的次数代码:class Solution {public: vector<string> commonChars(vector<string>& A) { vector<int> m(26,INT_MAX); vector&lt..

2020-10-14 11:32:16 111

原创 LeetCode 530. 二叉搜索树的最小绝对差

原题目:https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/思路:中序遍历,求解相邻接点的差值绝对值的最小值代码:class Solution { bool flag; int ans,pre; void dfs(TreeNode* root){ if(root == nullptr) return; dfs(root->left)..

2020-10-12 17:19:46 86

原创 LeetCode 75. 颜色分类

原题目:https://leetcode-cn.com/problems/sort-colors/思路:使用双指针,l记录当前左边到的位置,r记录右边到的位置为0,移动到前面。l++,cur++;为2移动到后面。r--。(此时不可以cur++,因为nums[r]使我们没有碰到过得元素)1时进行下一个元素的判断。cur++代码:class Solution {public: void sortColors(vector<int>& num..

2020-10-07 22:15:00 81

原创 LeetCode 834. 树中距离之和

原题目:https://leetcode-cn.com/problems/sum-of-distances-in-tree/思路:采用树形动态规划的思想。对于每一个节点来说,所有节点到他的距离之和的状态转移方程为:其中dp[v]代表以v为根的所有节点到他的距离,sz[v]表示已v为根的子树节点的数量。当一次遍历完,得到了所有节点的dp时,我们不需要以另一个节点为根重新遍历,只需要对树结构进行变化(官方解答的视频),所以每一次做变化我们只需要变换dp[u],sz[u],dp[v],s.

2020-10-06 23:13:05 188

原创 LeetCode 771. 宝石与石头

原题目:https://leetcode-cn.com/problems/jewels-and-stones/思路:构造哈希表代码:class Solution {public: int numJewelsInStones(string J, string S) { map<char,int> h; for(char& c:J) h[c] = 1; int sum = 0; for(c..

2020-10-02 15:28:31 77

原创 跑深度学习模型进行的日志输出

跑深度学习模型进行的日志输出构造Logger类进行输出重定向。在write函数中,使用两个函数使得命令行和日志都有输出class Logger(object): def __init__(self, filename='default.log', stream=sys.stdout): self.terminal = stream self.log = open(filename, 'a') def write(self, message): .

2020-10-02 14:35:19 1003

原创 nvidia-smi 实时刷新

watch -n0.1-dnvidia-smi #每隔0.1秒刷新一次

2020-09-30 11:59:46 1454

原创 LeetCode 79. 单词搜索

原题目:https://leetcode-cn.com/problems/word-search/思路:简单的回溯算法,开一个数组记录访问过得节点代码:class Solution { bool flag=false; void dfs(vector<vector<char>>& board,string& word,vector<vector<int>>& v,int x,int y,in..

2020-09-27 18:45:32 68

原创 LeetCode 60. 第k个排列

原题目:https://leetcode-cn.com/problems/permutation-sequence/思路:康拓展开代码:class Solution {public: string getPermutation(int n, int k) { vector<char> chs={'1','2','3','4','5','6','7','8','9'}; const int factor[]={1,1,2,6,24,120,720,5040..

2020-09-27 18:19:09 81

原创 LeetCode 235. 二叉搜索树的最近公共祖先

原题目:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/思路:利用二叉搜索树的性质代码:class Solution {public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(root->val > p->va..

2020-09-27 17:13:34 75

原创 LeetCode 501. 二叉搜索树中的众数

原题目:https://leetcode-cn.com/problems/find-mode-in-binary-search-tree/思路:对BST采用中序遍历,如果当前节点的值不等于前一节点的值,那么就对其进行判断,看看前一节点值得次数是否大于了maxn。分情况进行处理。细节:记得对中序遍历的第一个节点做初始化,中序遍历的最后一种节点在递归过程中是不会进行判断的(因为其后面没有节点和他进行比较),所以在main函数中,要对这一情况做单独的判断。代码:class S..

2020-09-25 14:05:24 69

原创 差分进化算法

1 简介最优化方法分为传统优化方法和启发式方法,传统的优化算法大多数都是利用目标函数的导数求解,而启发式优化方法以放生算法为主,通过启发式搜索策略实现求解优化,启发式搜索算法不要求目标函数连续,可微等信息,具有较好的全局寻优能力。是一种用于最优化问题的后设启发式算法,本质上是一种基于实数编码的具有保优思想的贪婪遗传算法。在AI领域,演化算法是演化计算的一个重要分支,基于群体的元启发式优化算法,具有自适应、自搜索、自组织和隐并行性等特点。目前演化算法广泛应用于求解无约束函数优化、约束函数优化、组合

2020-09-24 15:10:41 526

原创 LeetCode 896. 单调数列

原题目:https://leetcode-cn.com/problems/monotonic-array/思路:使用两个flag(a和b)来表明里面存在增和减的情况,如果两者同时出现,那么就不单调代码:class Solution {public: bool isMonotonic(vector<int>& A) { if(A.size() < 3) return true; int a=0,b=0; ..

2020-09-23 22:43:07 102

原创 LeetCode 617. 合并二叉树

原题目:https://leetcode-cn.com/problems/merge-two-binary-trees/思路:构造新的节点,判断递归的终止条件就可以代码:class Solution {public: TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { if(t1 ==nullptr) return t2; if(t2 == nullptr) return t1; ..

2020-09-23 22:18:24 71

原创 LeetCode 968. 监控二叉树

原题目:https://leetcode-cn.com/problems/binary-tree-cameras/思路:节点分为三种状态,1:该节点安装了监视器 2:该节点可观,但没有安装监视器 3:该节点不可观代码:class Solution { int ans = 0; int dfs(TreeNode* root){ if(root == NULL) return 1; int left = dfs(root->l...

2020-09-22 19:13:33 132

原创 LeetCode 1313. 解压缩编码列表

原题目:https://leetcode-cn.com/problems/decompress-run-length-encoded-list/代码:class Solution {public: vector<int> decompressRLElist(vector<int>& nums) { vector<int> ans; for(int i=1;i<nums.size();i+=2){ .

2020-09-20 17:07:07 98

原创 LeetCode 404. 左叶子之和

原题目:https://leetcode-cn.com/problems/sum-of-left-leaves/思路:递归的思想,只计算左叶子的节点值,那么怎么判断是不是左叶子呢,即当前节点指向的做孩子不为空,且做孩子是叶子节点,他就是左叶子代码:class Solution {public: int sumOfLeftLeaves(TreeNode* root) { if(root==nullptr) return 0; return..

2020-09-19 21:30:03 55

原创 LeetCode 47. 全排列 II

原题目:https://leetcode-cn.com/problems/permutations-ii/思路:对于全排列的扩展,只需要加上防重的判定条件代码:class Solution { vector<int> vis;public: void backtrack(vector<int>& nums, vector<vector<int>>& ans, int idx, vector&lt..

2020-09-18 22:38:58 168

原创 LeetCode 226. 翻转二叉树

原题目:https://leetcode-cn.com/problems/invert-binary-tree/思路:深度优先遍历,对每一个节点进行左右子树的翻转进行深度优先遍历的时候,可以尝试不构造新的递归函数,这样比较省时间。代码:class Solution {public: void dfs(TreeNode* root){ if(root==NULL) return ; TreeNode* t = root->lef..

2020-09-16 08:58:06 88

原创 LeetCode 637. 二叉树的层平均值

原题目:https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/思路:程序遍历,依次存入平均值即可代码:class Solution {public: vector<double> averageOfLevels(TreeNode* root) { if(root==NULL) return {}; vector<double> ans;..

2020-09-12 20:11:16 75

原创 LeetCode 1267. 统计参与通信的服务器

原题目:https://leetcode-cn.com/problems/count-servers-that-communicate/思路:记录每行每列的计算机的个数,然后依次遍历节点,如果该节点为计算机并且该行或该列的计算机个数大于1,则表示可以通信代码L:class Solution {public: int countServers(vector<vector<int>>& grid) { int m =grid..

2020-09-07 13:21:39 128

原创 LeetCode 1382. 将二叉搜索树变平衡

原题目:https://leetcode-cn.com/problems/balance-a-binary-search-tree/思路:获取中序遍历的结果,然后找去中点,此为根节点,依次递归的构造左子树和右子树代码:class Solution {public: vector<int> inorderSeq; void getInorder(TreeNode* o) { if (o->left) getInorder(o-..

2020-09-06 12:24:29 167

原创 LeetCode 1004. 最大连续1的个数 III

原题目:https://leetcode-cn.com/problems/max-consecutive-ones-iii/思路:滑动窗口代码:class Solution {public: int longestOnes(vector<int>& A, int K) { int maxlen =0; int left=0,right=0; while(right<A.size()){ ..

2020-09-06 12:20:02 84

原创 LeetCode 684. 冗余连接

原题目:https://leetcode-cn.com/problems/redundant-connection/思路:并查集,每次检查边的两个顶点是否属于同一个集合,如果是,则返回(形成了环)。如果不是,将这两个顶点并入到一个集合之中,依次检查所有的边。可以同时考虑路径压缩,每次合并的时候都合并到size大的节点。代码:class UnionFind{private: vector<int> parent; vector<int&gt..

2020-09-06 11:26:38 87

原创 LeetCode 1161. 最大层内元素和

原题目:https://leetcode-cn.com/problems/maximum-level-sum-of-a-binary-tree/思路:使用BFS,记录每一层的值之和,返回最大的层即可代码:class Solution {public: int maxLevelSum(TreeNode* root) { int maxlen=INT_MIN,ans,index=1; queue<TreeNode*> q; ..

2020-09-04 12:48:53 109

原创 LeetCode 1557. 可以到达所有点的最少点数目

原题目:https://leetcode-cn.com/problems/minimum-number-of-vertices-to-reach-all-nodes/思路:对示例的结果分析,我们只需找到入度为0的节点即可代码:class Solution {public: vector<int> findSmallestSetOfVertices(int n, vector<vector<int>>& edges) { ..

2020-09-04 11:57:08 119

原创 LeetCode 486. 预测赢家

原题目:https://leetcode-cn.com/problems/predict-the-winner/思路:当长度为偶数时,先手必获胜。采用动态规划,dp[i][j]表示两端是i,j时,两位选手的得分差值,显然dp[i][i] = nums[i],当i>j时,dp[i][j] = 0,状态转移方程:dp[i][j] = max(nums[i] - dp[i+1][j] , nums[j] - dp[i][j-1])代码:class Solution ...

2020-09-02 13:22:59 88

原创 LeetCode 491. 递增子序列

原题目:https://leetcode-cn.com/problems/increasing-subsequences/思路:利用DFS,采用剪枝和set去重就可以了。代码:class Solution { set<vector<int>> ans; void dfs(vector<int>& nums, vector<int>& tmp,int index){ if(tmp.si..

2020-08-25 14:32:18 100

原创 LeetCode 459. 重复的子字符串

原题目:https://leetcode-cn.com/problems/repeated-substring-pattern/思路:我们将两个s连在一起,并移除第一个和最后一个字符。如果s是该字符串的子串,那么s就满足题目要求。代码:class Solution {public: bool repeatedSubstringPattern(string s) { return (s + s).find(s, 1) != s.size();...

2020-08-24 14:42:11 100

原创 LeetCode 剑指 Offer 18. 删除链表的节点

原题目:https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/代码:class Solution {public: ListNode* deleteNode(ListNode* head, int val) { if(head == NULL) return head; ListNode* hair=new ListNode(0),*pre; hair.

2020-08-23 09:16:37 79

原创 LeetCode 201. 数字范围按位与

原题目:https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/思路一:如果有一位是0,那么该位最终就会是0,基于此,算法描述如下:找出公共前缀,左移。公共前缀,m>>1,n>>1直到两者相等思路二:Brian Kernighan 算法。用于清除二进制串最右边的一。基于此,我们可以找到公共前缀代码:class Solution {public: int ran...

2020-08-23 08:42:51 78

原创 LeetCode 328. 奇偶链表

原题目:https://leetcode-cn.com/problems/odd-even-linked-list/代码:class Solution {public: ListNode* oddEvenList(ListNode* head) { if(head==NULL) return head; ListNode*p,*q,*t; p = head;q=head; while(q->next&&a.

2020-08-22 09:48:19 82

原创 LeetCode 面试题 02.07. 链表相交

原题目:https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci/思路:按引用相等,可以使用=判别。代码:class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode* p,*q; p = headA,q=headB;..

2020-08-22 08:57:30 194

空空如也

空空如也

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

TA关注的人

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