leetcode-hot100
toRenee_016
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode-hot100 6.只出现一次的数字 (cpp)
图片来自leetcode //利用异或,异或满足交换定律,相同的异或结果为0,与0异或结果为本身 class Solution { public: int singleNumber(vector<int>& nums) { int res = 0; for (auto i = nums.begin(); i < nums.end(); i++) { ...原创 2019-12-14 15:29:45 · 213 阅读 · 0 评论 -
leetcode-hot100 5.翻转链表 (cpp)
图片来自leetcode class Solution { public: ListNode* reverseList(ListNode* head) { ListNode* Prev=NULL; ListNode* Node = head; ListNode* newhead = NULL; while (Node != NULL) { ListNode* Nod...原创 2019-12-12 21:31:09 · 228 阅读 · 0 评论 -
leetcode-hot100 4.二叉树的最大深度 (cpp)
图片来自LeetCode class Solution { public: int maxDepth(TreeNode* root) { if (root == NULL) return 0; int Lth = maxDepth(root->left); int Rth = maxDepth(root->right); return max(Lth, Rth...原创 2019-12-12 21:10:52 · 211 阅读 · 0 评论 -
leetcode-hot100 3.翻转二叉树 (cpp)
图片来自leetcode //先序遍历,注意交换前的保存 class Solution { public: TreeNode* invertTree(TreeNode* root) { if (root == NULL) { return NULL; } TreeNode* leftroot = root->left; root->lef...原创 2019-12-12 21:00:00 · 174 阅读 · 0 评论 -
leetcode-hot100 2.合并二叉树 (cpp)
//树的先序遍历,分左右,先做操作,再递归 class Solution { public: TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { if (t1 == NULL) return t2; if (t2 == NULL) return t1; t1->val = t1->val + t2->...原创 2019-12-12 20:28:54 · 177 阅读 · 0 评论 -
leetcode-hot100 1. 打家劫舍III (cpp)
//对于相邻的两层节点,第一层右边的节点和第二层左边的节点完全可以求和的!!所以不能用层次遍历求和来迁移到一维DP计算 //树状DP 自底向上 #include<iostream> #include<unordered_map> #include<algorithm> using namespace std; struct TreeNode { int v...原创 2019-12-11 16:44:02 · 164 阅读 · 0 评论
分享