摘要:
scanf() ####函数会根据参数中的转义说明获取对应的值的类型,在获取值的时候会自动跳过前面的若干空格、制表符以及换行符(\n),如下图所示。 ####scanf()只会获取第一个符合转移说明的值,如果没有获取到那么原本输入队列中的值不会改变,仍旧在输入队列中。 ####scanf()只会回去 阅读全文
posted @ 2022-11-29 17:38
破忒头头
阅读(159)
评论(0)
推荐(0)
双指针 class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { int l = 0,r = numbers.size()-1,sum=0; while(l<r){ sum = numbers[l] 阅读全文
class Solution { public: bool checkPossibility(vector<int>& nums) { int n = nums.size(); for(int i=0;i<n-1;i++){ int x = nums[i],y = nums[i+1]; if(x>y 阅读全文
首先根据身高从小到大排序如果身高相等那么根据第二个值降序排序 class Solution { public: vector<vector<int>> reconstructQueue(vector<vector<int>>& people) { int n = people.size(); sor 阅读全文
就是不断寻找最长的非递增序列 class Solution { public: int maxProfit(vector<int>& prices) { if(prices.empty()||prices.size()<2){ return 0; } int i=0; int res = 0; in 阅读全文
1、一上来先遍历数组,找到每个字母最后出现的位置。 2、再次遍历数组,保持一个last,表示当前至少应该在哪里分割 class Solution { public: vector<int> partitionLabels(string s) { //先遍历一遍数组,记录每一个字母最后出现的位置; i 阅读全文
贪心 1、先按照所有起球的右边界排序,记录第一个气球的右边界位置,如果后续气球的左边界小于记录中的值那么这个气球就是可以被箭射中的,这种情况不做处理。 2、当出现遍历的时候某一个起球的左边界大于当前记录中的值的时候,那么此时第一个箭就射不中当前的气球了,所以箭的数量++,并且记录中的值等于当前遍历气 阅读全文
贪心 class Solution { public: bool canPlaceFlowers(vector<int>& flowerbed, int n) { int m = flowerbed.size(); int pre = -1; for(int i=0;i<m;i++){ //寻找区间 阅读全文