374.猜数字大小
题目链接
static const auto io_speed_up = []()
{
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}();
int guess(int num);
class Solution {
public:
typedef long long LL;
int guessNumber(int n) {
LL l = 1, r = n;
while(l<r){
LL m = (l + r)>>1;
if(guess(m) > 0)l = m + 1;
else r = m;
}
return l;
}
};
383.赎金信
题目链接
static const auto io_speed_up = []()
{
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}();
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int ms[26]={0};
for(char p : magazine)ms[p-'a']++;
for(char p : ransomNote)if(--ms[p-'a']<0)return 0;
return 1;
}
};