![](https://img-blog.csdnimg.cn/9a30777adb4746dc882a1ba80a8567b6.jpeg?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode
刷题
CaptainDrake
log(you ? peace : love)
展开
-
455. 分发饼干
力扣 假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。 对每个孩子 i,都有一个胃口值g[i],这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j,都有一个尺寸 s[j]。如果 s[j]>= g[i],我们可以将这个饼干 j 分配给孩子 i ,这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/assign-co...原创 2022-03-20 20:22:46 · 69 阅读 · 0 评论 -
383. 赎金信
力扣 给你两个字符串:ransomNote 和 magazine ,判断 ransomNote 能不能由 magazine 里面的字符构成。 如果可以,返回 true ;否则返回 false 。 magazine 中的每个字符只能在 ransomNote 中使用一次。 Plan1:暴力法 class Solution { public: bool canConstruct(string ransomNote, string magazine) { for(int ...原创 2022-03-13 00:02:10 · 326 阅读 · 0 评论 -
454. 四数相加 II
力扣 给你四个整数数组 nums1、nums2、nums3 和 nums4 ,数组长度都是 n ,请你计算有多少个元组 (i, j, k, l) 能满足: 0 <= i, j, k, l < n nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0 class Solution { public: int fourSumCount(vector<int>& A, vector<int>&...原创 2022-03-11 17:40:12 · 57 阅读 · 0 评论 -
1. 两数之和
力扣 给定一个整数数组 nums和一个整数目标值 target,请你在该数组中找出 和为目标值 target的那两个整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { std::uno...原创 2022-03-11 16:59:05 · 58 阅读 · 0 评论 -
202. 快乐数
力扣 class Solution { public: //注意问题:无限循环 //函数:求出一个数字中每个数字的乘方和 int getSum(int x){ int sum = 0; while(x){ sum += (x % 10)*(x % 10); x /= 10; } return sum;原创 2022-03-11 15:55:22 · 57 阅读 · 0 评论 -
有效的字母异位词
力扣 思想: 采用哈希映射:将a-z映射为26个数字 具体算法实现:将字符串s和t中的字符转化为数字 看图: 字符相同就在数字上 减去1 如果最后每个数字次数都为0,那么s和t就为 字母异位词 class Solution { public: bool isAnagram(string s, string t) { int record[26] = {0}; for (int i = 0; i < s.siz...原创 2022-03-10 23:35:33 · 86 阅读 · 0 评论