摘要:
贪心 121.买卖股票的最佳时机 class Solution { public: int maxProfit(vector<int>& prices) { //只需要后面卖出的价格>前面买入价格(不用连续区间递增的) int minprice=1e9; int maxprofit=0; for(a 阅读全文
摘要:
动态规划 70.爬楼梯 转换方程:dp[i]=dp[i-1]+dp[i-2] 思路:爬到第i节台阶前的前1节是一步或前两节是一步。 本题类似于斐波拉契数列 动态规划的方法利用的是数组比用递归函数时间复杂度好 class Solution { public: int climbStairs(int n 阅读全文
摘要:
第一天算法2025/8/13 复习内容:二分 2.P1102 A-B #include<bits/stdc++.h> using namespace std; const int N=2e5+6; int a[N]; map<int,int>mp;//存放数组里每个数出现次数 int main(){ 阅读全文