算法
Paranoia_yy
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
俄罗斯套娃信封(最长递增子序列进阶)
bool const cmp(const vector<int>& A, const vector<int>& B){ if(A[0]==B[0]) return A[1]<B[1]; return A[0]<B[0]; } class Solution { public: int maxEnvelopes(vector<vector<int>>& envelopes) {原创 2021-03-04 14:37:42 · 192 阅读 · 1 评论 -
122. 买卖股票的最佳时机 II
动态规划 dp[i]表示第i天可以赚取的最大收益。 动态转移方程:dp[i] = max(dp[i-1],dp[i-1]+prices[i]-prices[i-1])。 初始值dp[0]表示初始收益为0。 class Solution { public: int maxProfit(vector<int>& prices) { int n = prices.size(); vector<int> dp(n,0); for原创 2020-11-09 00:02:45 · 122 阅读 · 0 评论 -
Leetcode121. 买卖股票的最佳时机
Leetcode121. 买卖股票的最佳时机 1.找出某个元素与他右侧元素最大差值 class Solution { public: int maxProfit(vector<int>& prices) { int min_price = 1e9, max_profit = 0; for(int price:prices){ max_profit = max(max_profit, price - min_price);原创 2020-11-06 15:19:27 · 329 阅读 · 0 评论 -
最长递增子序列
本题中的子序列可以不是连续的 如 2 7 3 5中最长递增子序列为 2 3 5 int lengthOfLIS(vector<int>& nums) { int n = nums.size(); if(n < 2)return n; //dp[i]表示在0-i个数字中,选中nums[i]这个数字可以构成的最长子序列个数 vector<int> dp(n, 1); int ans = 1;原创 2021-03-04 13:28:50 · 145 阅读 · 1 评论 -
内置函数总结(待更新)C++
C++ __builtin_popcount(num) //比特位计数 Go bits.OnesCount原创 2021-03-03 12:31:00 · 203 阅读 · 0 评论
分享