摘要: 题目地址:https://leetcode-cn.com/problems/binary-tree-preorder-traversal/ 解题思路:树构造以及递归遍历 class Solution { vector<int> ans; public: vector<int> preorderTra 阅读全文
posted @ 2020-10-27 10:54 CCxiao5 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/ 解题思路:遍历一遍,累计求和 class Solution { public: vector<int> smalle 阅读全文
posted @ 2020-10-26 10:54 CCxiao5 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/complement-of-base-10-integer/ 解题思路:按位取反计算。注意不要想当然使用~,~10等于-11,而不是5。数据是以补码存储的,在计算机中,10的原码和补码为00...1010。取反后,补码变成1 阅读全文
posted @ 2020-10-23 17:05 CCxiao5 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/palindrome-linked-list/ 解题思路: 用一个数组装; class Solution { public: bool isPalindrome(ListNode* head) { ListNode *q; 阅读全文
posted @ 2020-10-23 16:17 CCxiao5 阅读(52) 评论(0) 推荐(0) 编辑
摘要: 第一步:换清华源(.condarc),需要注意是http不是https channels: - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ - http://mirrors.tuna.tsinghua.edu.cn/anaconda 阅读全文
posted @ 2020-10-22 10:18 CCxiao5 阅读(3558) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/k-th-symbol-in-grammar/ 解题思路:找规律,第N行前半部分是第N-1行,后半部分是第N-1行按位取反。 class Solution { public: int kthGrammar(int N, in 阅读全文
posted @ 2020-10-21 18:26 CCxiao5 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/long-pressed-name/ 解题思路:暴力,判断返回false的几种情况。 class Solution { public: bool isLongPressedName(string name, string t 阅读全文
posted @ 2020-10-21 17:53 CCxiao5 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/divide-two-integers/ 解题思路:按照计算机实现除法运算来进行求解。这题需要注意的是:只能存储 32 位有符号整数,最小整型数值的相反数会越界,所以需要使用longlong类型。 注意:如果用VS编译调试, 阅读全文
posted @ 2020-10-20 15:16 CCxiao5 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/implement-strstr/ 解题思路:KMP算法。该题注意的是string类的size()方法返回的是无符号的值。 简单说一下KMP算法。KMP算法就是在暴力匹配的算法中引入next数组,匹配的时候如果不匹配只更新模 阅读全文
posted @ 2020-10-15 21:02 CCxiao5 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/remove-element/ 解题思路:设置新的下标 class Solution { public: int removeElement(vector<int>& nums, int val) { if (nums.si 阅读全文
posted @ 2020-10-12 19:34 CCxiao5 阅读(81) 评论(0) 推荐(0) 编辑