189. 轮转数组
【参考代码】
class Solution {
public:
void rotate(vector<int>& nums, int k) {
int size = nums.size();
if(1 == size)
{
return;
}
vector<int> temp(size);
//k = k % size;
for(int i=0; i<size; i++)
{
temp[(i + k) % size] = nums[i];
}
nums = temp;
}
};
383. 赎金信
【参考代码】
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
//子串是ransomNote,父串是magazine,判断父串是否包含子串
int cnt[26] = {0};
if(ransomNote.size() > magazine.size() || ransomNote.size() == 0)
{
return false;
}
for(char c : magazine)
{
cnt[c - 'a']++;
}
for(char c : ransomNote)
{
cnt[c - 'a']--;
if(cnt[c - 'a'] < 0)
return false;
}
return true;
}
};