摘要: 第一题 题目链接:https://leetcode.cn/problems/fei-bo-na-qi-shu-lie-lcof/ 个人题解:迭代即可,可以减少空间复杂度,只需要使用常数级别的空间即可。 代码: const int mod=1e9+7; class Solution { public: 阅读全文
posted @ 2022-05-10 22:26 黑VS白-清墨 阅读(27) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode.cn/problems/shu-de-zi-jie-gou-lcof/ 个人题解:递归判断即可,先写一个判断函数,再在函数里面递归调用即可。 代码: class Solution { public: bool judge(TreeNode* A,T 阅读全文
posted @ 2022-05-09 14:36 黑VS白-清墨 阅读(20) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode.cn/problems/di-string-match/ 个人题解:贪心算法,每次把最小和最大的排在一起,用双指针来进行移动即可 代码: class Solution { public: vector<int> diStringMatch(string s 阅读全文
posted @ 2022-05-09 14:02 黑VS白-清墨 阅读(21) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/ 个人题解:BFS即可 代码: /** * Definition for a binary tree node. * struct 阅读全文
posted @ 2022-05-08 16:24 黑VS白-清墨 阅读(30) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/ 个人题解:因为空间复杂度有限制,要使用常数的空间,因此只能在数组里转换。 根据题目要求,重复的数字是出现了2次。 因此,我们可以遍历数组,将下标 \(x\) 阅读全文
posted @ 2022-05-08 15:46 黑VS白-清墨 阅读(20) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/ 个人题解:因为矩阵元素的特殊性,因此可以一行一行或者一列一列查找 代码: class Solution { public: bool fin 阅读全文
posted @ 2022-05-07 19:37 黑VS白-清墨 阅读(25) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/minimum-genetic-mutation/ 个人题解:DFS 在 \(bank\) 中找到与 \(start\) 相差一个字符的字符串; 判断这个字符串在没在集合里面 \(cnt++\) ,递归 \(cnt--\) 阅读全文
posted @ 2022-05-07 19:24 黑VS白-清墨 阅读(21) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/ 个人题解:索引法 我们可以将数字和下表进行对应,每次把索引和下标一样的数字记录(强行变成) 当我们再次遍历的时候如果下标一样,就一定会有重复 阅读全文
posted @ 2022-05-06 10:54 黑VS白-清墨 阅读(20) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/number-of-recent-calls/ 个人题解:用队列来维护即可 代码: class RecentCounter { public: queue<int> q; RecentCounter() { } int pi 阅读全文
posted @ 2022-05-06 10:21 黑VS白-清墨 阅读(17) 评论(0) 推荐(0)
摘要: 第一题 题目链接:https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/ 个人题解:遍历,当碰到空格,抹去空格,插入字符串。 代码: class Solution { public: string replaceSpace(string s) { 阅读全文
posted @ 2022-05-05 11:09 黑VS白-清墨 阅读(30) 评论(0) 推荐(0)