随笔分类 -  LeetCode

摘要:巴什博奕,n%(m+1)!=0时,先手总是会赢的 如果n是4的倍数,无论怎么拿都输;反之,可以拿去相应的石子让对手面对4的倍数 阅读全文
posted @ 2022-05-20 16:03 智人心 阅读(21) 评论(0) 推荐(0) 编辑
摘要:注意二叉树的深度遍历即先序、中序、后序遍历之一,sprintf中char c[n]的长度包括'\0'即数字的长度+1,在数字是-100时最长,长度为4+1即5,char c[4]会溢出 /** * Definition for a binary tree node. * struct TreeNod 阅读全文
posted @ 2022-05-20 15:44 智人心 阅读(18) 评论(0) 推荐(0) 编辑
摘要:利用到了并查集相关的知识,贴出压缩路径,按秩合并的代码 https://blog.csdn.net/weixin_38279101/article/details/112546053 //并查集类 class DisJointSetUnion { private: // 所有根结点相同的结点位于同一 阅读全文
posted @ 2022-05-20 13:25 智人心 阅读(60) 评论(0) 推荐(0) 编辑
摘要:虽然过了,但是还是不是很清楚,中序遍历,访问每个非空节点时,将左指针置空,pre记录每个父节点,父节点的right置为当前节点 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *le 阅读全文
posted @ 2022-05-18 21:16 智人心 阅读(30) 评论(0) 推荐(0) 编辑
摘要:目前只能暴破,应该有更高效的算法 阅读全文
posted @ 2022-05-13 20:22 智人心 阅读(4) 评论(0) 推荐(0) 编辑
摘要:char转string的时候注意char数组的最后一个字符要是'\0' 阅读全文
posted @ 2022-05-13 20:10 智人心 阅读(20) 评论(0) 推荐(0) 编辑
摘要:set的添加: set<string>s; s.insert("abc"); 阅读全文
posted @ 2022-05-13 19:52 智人心 阅读(18) 评论(0) 推荐(0) 编辑
摘要:注意仅有一个字符不相等是false 阅读全文
posted @ 2022-05-13 14:55 智人心 阅读(19) 评论(0) 推荐(0) 编辑
摘要:注意 1: left join 用的是on而不是where 2: 如果空则赋0 ifnull(sum(r.distance,0) select u.name name,ifnull(sum(r.distance),0) travelled_distance from Users u left joi 阅读全文
posted @ 2022-05-13 13:44 智人心 阅读(28) 评论(0) 推荐(0) 编辑
摘要:利用unordered_map<int,int>hashmap可以将查找的时间缩小至O(1) class Solution { public: vector<int> arrayRankTransform(vector<int>& arr) { int n = arr.size(),MIN,MINP 阅读全文
posted @ 2022-05-13 09:04 智人心 阅读(14) 评论(0) 推荐(0) 编辑
摘要:没办法,背下来吧 import java.text.*; import java.util.*; import java.lang.*; class Solution { public int daysBetweenDates(String date1, String date2){ int day 阅读全文
posted @ 2022-05-12 21:44 智人心 阅读(16) 评论(0) 推荐(0) 编辑
摘要:char数组转string 方法1: string str(ch); 方法2: string str = ch; 方法3(对string进一步操作): string s0 = ch; string s3 (s0, 8, 3); 阅读全文
posted @ 2022-05-12 21:13 智人心 阅读(20) 评论(0) 推荐(0) 编辑
摘要:判断两个矩形的边所在直线关系即可 class Solution { public: bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) { return !(rec1[0]>=rec2[2]||rec1[2]<=rec2[0]| 阅读全文
posted @ 2022-05-12 19:25 智人心 阅读(17) 评论(0) 推荐(0) 编辑
摘要:map<string,int>的用法 map<string,int>mp; mp["abc"]++; 阅读全文
posted @ 2022-05-12 14:05 智人心 阅读(22) 评论(0) 推荐(0) 编辑
摘要:三角形面积计算公式: 参考 https://baike.baidu.com/item/%E4%B8%89%E8%A7%92%E5%BD%A2%E9%9D%A2%E7%A7%AF%E5%85%AC%E5%BC%8F/8491990 阅读全文
posted @ 2022-05-12 12:47 智人心 阅读(46) 评论(0) 推荐(0) 编辑
摘要:set的添加: set<string>wSet; string s = "sss"; wSet.insert(s); 遍历: for (auto it = wSet.cbegin(); it != wSet.cend(); it++){ cout<<*it<<endl; } 删除: wSet.era 阅读全文
posted @ 2022-05-12 12:21 智人心 阅读(25) 评论(0) 推荐(0) 编辑
摘要:巧妙的转化思想: n-1个数都加1相当于最大数减1 结果就是每个数减去最小数差的总和 阅读全文
posted @ 2022-05-10 14:45 智人心 阅读(15) 评论(0) 推荐(0) 编辑
摘要:注意两点: 1.int转化成string: int start; stringstream ss; string s; ss<<start; s = ss.str(); 2.stringstream的清空操作: ss.str(""); 注: 据说 ss.clear(); //clear flags. 阅读全文
posted @ 2022-05-10 14:14 智人心 阅读(16) 评论(0) 推荐(0) 编辑
摘要:注意变量的类型 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t result = 0,a[32],j; int i; for(i=0;i<32;i++){ a[i] = n%2; n /= 2; } for(i 阅读全文
posted @ 2022-05-10 13:43 智人心 阅读(15) 评论(0) 推荐(0) 编辑
摘要:先在m*n矩阵中匹配word[0]和board[i][j] 如果匹配成功让word的子序列(除去word[0])进入dfs回溯法 在dfs中每次比较四周字符与word[0],如果匹配成功,再令word的子序列进入dfs直至word序列为空返回true 如果某次匹配不成功,则回溯,将相应flag标记置 阅读全文
posted @ 2022-05-10 11:11 智人心 阅读(18) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示