随笔分类 -  leetcode

摘要:涉及unordered_set类型的使用,包括find()、insert()、erase()函数使用。 滑动窗口:当前字符串不存在字串中,直接插入;若存在,将最左边的元素一直移除直到不存在。这样相当于遍历了所有无重复连续字串。 class Solution { public: int lengthO 阅读全文
posted @ 2020-03-29 14:45 比特的脉搏 阅读(164) 评论(0) 推荐(0)
摘要:将数组的 下标、值 作为 值-键 对放入map ,用find函数查找,时间复杂度为o(n)降为o(1)。 拿空间换时间,能达到去重的目的。 当然存放还是需要o(n)的时间复杂度,可用于o(n^2)降为o(n)。 map<int,int> m; m[arr[index]] = index; if(m. 阅读全文
posted @ 2020-03-29 14:37 比特的脉搏 阅读(1132) 评论(1) 推荐(0)
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ ListNode * 阅读全文
posted @ 2020-03-29 14:35 比特的脉搏 阅读(99) 评论(0) 推荐(0)