摘要: 题目 给定两个数组,编写一个函数来计算它们的交集。 分析 数组元素值可以很大,所以不适合直接开数组进行哈希,这里要学习另一种哈希方式:集合 集合有三种,区别见下面代码随想录的Carl大佬的表格,总结的很清晰。 由于题目中明确了不考虑元素的是否有序,所以我们可以使用unordered_set,这样查删 阅读全文
posted @ 2021-01-17 17:29 Uitachi 阅读(102) 评论(0) 推荐(0)
摘要: 题目 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 代码 法一、排序后判断是否相等,因为题目中说了字符串都为26个小写字母。 t 是 s 的异位词等价于两个字符串排序后相等。以后要学会这个技巧 1 class Solution { 2 public: 3 bool 阅读全文
posted @ 2021-01-17 15:57 Uitachi 阅读(79) 评论(0) 推荐(0)
摘要: 问题 安装好了vscode并且装上code runner插件后,运行代码时总是弹出powershell,而不是在vscode底部终端 显示运行结果。 解决方法 打开系统cmd ,在窗口顶部条右击打开属性,把最下面的旧版控制台选项取消,即可 阅读全文
posted @ 2021-01-17 11:26 Uitachi 阅读(2260) 评论(0) 推荐(0)
摘要: 一、getchar()和cin.get() getchar()会将开头的空格或者回车作为输入 1 #include<iostream> 2 using namespace std; 3 int main(){ 4 char ch1 = getchar(); 5 char ch2 = getchar( 阅读全文
posted @ 2021-01-17 11:18 Uitachi 阅读(194) 评论(0) 推荐(0)
摘要: 同LeetCode226翻转二叉树 1 class Solution { 2 public: 3 TreeNode* mirrorTree(TreeNode* root) { 4 if(root == NULL) return NULL; 5 TreeNode* node = root->left; 阅读全文
posted @ 2021-01-15 17:29 Uitachi 阅读(51) 评论(0) 推荐(0)
摘要: 题目 class Solution { public: int ans = 0; int sumRootToLeaf(TreeNode* root) { dfs(root,0); return ans; } void dfs(TreeNode*root,int cur){ if(root== NUL 阅读全文
posted @ 2021-01-14 18:19 Uitachi 阅读(64) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 TreeNode* r1;TreeNode* r2; 4 bool isCousins(TreeNode* root, int x, int y) { 5 dfs(root,r1,x); 6 dfs(root,r2,y); 7 in 阅读全文
posted @ 2021-01-13 17:47 Uitachi 阅读(93) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 int flag = 0; 4 bool isUnivalTree(TreeNode* root){ 5 isUnivalTree1(root,root->val); 6 if(flag == 0) return true; 7 e 阅读全文
posted @ 2021-01-13 16:32 Uitachi 阅读(65) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 int sum = 0; 4 int rangeSumBST(TreeNode* root, int low, int high) { 5 dfs(root,low,high); 6 return sum; 7 } 8 void d 阅读全文
posted @ 2021-01-13 16:13 Uitachi 阅读(82) 评论(0) 推荐(0)
摘要: 题目 法一、自己 1 class Solution { 2 public: 3 vector<int>res; 4 TreeNode* increasingBST(TreeNode* root) { 5 dfs(root); 6 TreeNode* p = new TreeNode(0); 7 Tr 阅读全文
posted @ 2021-01-13 16:08 Uitachi 阅读(80) 评论(0) 推荐(0)