随笔分类 - 刷题记录
摘要:两个数组的交集 链接349. 两个数组的交集 - 力扣(LeetCode) class Solution { public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { unordered_set<int> r
阅读全文
摘要:有效的字母异位词 题目链接242. 有效的字母异位词 - 力扣(LeetCode) class Solution { public: bool isAnagram(string s, string t) { int record[26] = {0}; for(int i = 0; i < s.siz
阅读全文
摘要:链表相交 题目链接面试题 02.07. 链表相交 - 力扣(LeetCode) class Solution { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode* curA = he
阅读全文
摘要:反转链表 题目链接206. 反转链表 - 力扣(LeetCode) class Solution { public: ListNode* reverseList(ListNode* head) { ListNode* temp; ListNode* cur = head; ListNode* pre
阅读全文
摘要:移除链表元素 题目链接203. 移除链表元素 - 力扣(LeetCode) class Solution { public: ListNode* removeElements(ListNode* head, int val) { ListNode* varHead = new ListNode(0)
阅读全文
摘要:长度最小的子数组 题目链接209. 长度最小的子数组 - 力扣(LeetCode) 看似很简单。看完滑动窗口法的时候觉得很容易理解,时间复杂度O(n)的推导也理解。无非就是两个指针,因为题目要求子串必连续。 所以一个循环内嵌套一个慢指针,剔除大于目标值的部分 写的时候就漏了很多细节。第一次提交,条件
阅读全文
摘要:移除元素 题目链接 27. 移除元素 - 力扣(LeetCode) class Solution { public: int removeElement(vector<int>& nums, int val) { int slotIndex = 0; for(int fastIndex = 0; f
阅读全文
摘要:二分查找基础: 二分查找 题目链接 Loading Question... - 力扣(LeetCode) 最开始的题解: class Solution { public: int search(vector<int>& nums, int target) { int left = 0 ; int r
阅读全文

浙公网安备 33010602011771号