LeetCode
qq_41699013
这个作者很懒,什么都没留下…
展开
-
跳跃游戏III
BFS跳跃游戏III#include<bits/stdc++.h>using namespace std;class Solution {public: bool canReach(vector<int>& arr, int start) { if (arr[start] == 0) return true; int n = arr.size(); vector<bool> st(n);//这里写原创 2022-01-16 12:38:40 · 2498 阅读 · 0 评论 -
LeetCode 406. Queue Reconstruction by Height
原题链接思路:1.贪心将身高从高到低排序。因为身高更高的人要求更少,优先插入更高的人。若两者身高相同,先插入条件少的(看到的人更少)。#include<vector>class Solution {public: vector<vector<int>> reconstructQueue(vector<vector<int>>& p) { sort(p.begin(), p.end(), [](vector原创 2021-08-18 16:42:10 · 78 阅读 · 0 评论 -
LeetCode 122. Best Time to Buy and Sell Stock II
原题链接class Solution {public: int maxProfit(vector<int>& prices) { int n=prices.size(); int res = 0; for (int i = 1; i < n; i++) { if (prices[i] > prices[i - 1]) { res += prices[i] - prices[i原创 2021-08-18 15:16:48 · 75 阅读 · 0 评论 -
LeetCode 763. 划分字母区间
763class Solution {public: vector<int> partitionLabels(string s) { vector<int> res; unordered_map<char, int> last;//哈希表,存放字母最后出现的位置 for (int i = 0; i < s.size(); i++) { last[s[i]] = i;原创 2021-08-18 11:15:43 · 40 阅读 · 0 评论 -
LeetCode 452. 用最少数量的箭引爆气球
452在二维空间中有许多球形的气球。对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标。由于它是水平的,所以纵坐标并不重要,因此只要知道开始和结束的横坐标就足够了。开始坐标总是小于结束坐标。一支弓箭可以沿着 x 轴从不同点完全垂直地射出。在坐标 x 处射出一支箭,若有一个气球的直径的开始和结束坐标为 xstart,xend, 且满足 xstart ≤ x ≤ xend,则该气球会被引爆。可以射出的弓箭的数量没有限制。 弓箭一旦被射出之后,可以无限地前进。我们想找到使得所有气球全部被引爆,所原创 2021-08-18 10:14:16 · 46 阅读 · 0 评论 -
LeetCode 605:Can Place Flowers
605贪心即可假设你有一个很长的花坛,一部分地块种植了花,另一部分却没有。可是,花卉不能种植在相邻的地块上,它们会争夺水源,两者都会死去。给定一个花坛(表示为一个数组包含 0 和 1,其中 0 表示没种植花,1 表示种植了花),和一个数 n 。能否在不打破种植规则的情况下种入 n 朵花?能则返回 True,不能则返回 False。class Solution {public: bool canPlaceFlowers(vector<int>& flowerbed, in原创 2021-08-18 09:29:52 · 52 阅读 · 0 评论 -
Leetcode刷题:135
CandyThere are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children wit原创 2021-08-16 16:02:45 · 51 阅读 · 0 评论