有效的字母异位词
class Solution {
public:
bool isAnagram(string s, string t) {
int record[26] = {0};
for(int i = 0; i < s.size(); ++i)
{
record[s[i] - 'a']++;
}
for(int i = 0; i < t.size(); ++i)
{
record[t[i] - 'a']--;
}
for(int i = 0; i < 26; ++i)
{
if(record[i] != 0)
{
return false;
}
}
return true;
}
};
两个数组的交集
class Solution {
public:
vector
unordered_set
unordered_set
for(int num : nums2)
{
if(nums_set.find(num) != nums_set.end())
{
result.insert(num);
}
}
return vector
}
};
快乐数
class Solution {
public:
vector
unordered_set
unordered_set
for(int num : nums2)
{
if(nums_set.find(num) != nums_set.end())
{
result.insert(num);
}
}
return vector
}
};
两数之和
class Solution {
public:
vector
vector
unordered_map<int, int> map;
for(int i = 0; i < nums.size(); ++i)
{
if(map.find(target - nums[i]) != map.end())
{
ret.push_back(map[target - nums[i]]);
ret.push_back(i);
}
else
{
map.insert(pair<int,int>(nums[i],i));
}
}
return ret;
}
};
标签:set,end,nums,int,day5,vector,result,打卡 From: https://www.cnblogs.com/pwangikun/p/18368068