- 博客(4)
- 收藏
- 关注
原创 C++ 结构体 运算符重载 const使用问题
问题 在刷题的时候经常会遇到需要自己写结构体并且自己重载比较函数的情况,特别是有时候需要用一些STL容器(如priority_queue)储存结构体的时候。在重载比较函数的时候有些疑惑于哪里需要加const,所以今天总结一下。 看下面的简单例子: struct Student{ int ID; bool operator<(const Student &student...
2020-02-05 03:12:13 1179
原创 Leetcode 1315 Sum of Nodes with Even-Valued Grandparent |dfs
题目链接:leetcode1315 题目简述: 本题给定一个二叉树,求所有祖父节点为偶数的节点的和(祖父节点就是父节点的父节点) 题目思路: 本题采用递归的方法,设置一个标志位flag来记录父节点和祖父节点是偶数还是奇数。根据flag的值以及当前节点的数值的奇偶决定递归调用时的新flag。flag值: 0-父节点和祖父节点都为奇数;1-只有父节点为偶数;2-只有祖父节点为偶数;3-父节点和祖父节点...
2020-01-12 11:16:51 335
原创 Leetcode 582 Kill Process -递归reparent
题目链接leetcode582 题目简述: 本题是算法在操作系统的应用,每个process(进程)都有pid(process id),每个process都有唯一的父进程,用ppid (parent process id)代表,每个process可以有多个children process(子进程)。当我们kill某个process的时候,需要把它所有的children process也kill掉。所...
2020-01-07 13:53:54 441 1
原创 Leetcode 241 Different Ways to Add Parentheses - 分治法+递归
Leetcode 241 Different Ways to Add Parentheses - 分治法+递归 题目: Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and op...
2020-01-04 08:31:47 179
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人