摘要:
A:水题,求数组中只出现一次的元素的和。 1 class Solution { 2 public: 3 int sumOfUnique(vector<int>& nums) { 4 unordered_map<int,int> m; 5 for(auto x:nums){ 6 m[x]++; 7 } 阅读全文
posted @ 2021-02-09 21:44
greenofyu
阅读(75)
评论(0)
推荐(0)
摘要:
https://www.acwing.com/problem/content/1416/ 给定一串序列,要找到异或值最大的子串。 在保证右端点最小的前提下保证长度最小。 对于异或的性质 a^b^a = b,可以将前缀和应用于该题。 这样的话只需要枚举左端点和右端点,但是时间复杂度为n^2,计算之后达 阅读全文
posted @ 2021-02-09 15:54
greenofyu
阅读(68)
评论(0)
推荐(0)
摘要:
Trie树查找和插入的时间复杂度均为O(n)。 https://www.acwing.com/problem/content/837/ 1 #include<iostream> 2 using namespace std; 3 const int N=1e5+10;//输入字符串的总长度为1e5+1 阅读全文
posted @ 2021-02-09 11:40
greenofyu
阅读(88)
评论(0)
推荐(0)
摘要:
https://www.acwing.com/problem/content/427/ 水题。 unique函数是将相邻的相同的元素去除掉,返回的是最后一个元素的下一个迭代器,时间复杂度为n。 1 #include<algorithm> 2 #include<iostream> 3 using na 阅读全文
posted @ 2021-02-09 11:03
greenofyu
阅读(65)
评论(0)
推荐(0)
浙公网安备 33010602011771号