摘要: ###一. 数组 添加线性,访问常数 class MedianFinder { public: MedianFinder() { n = 0; } void addNum(int num) { n++; nums.push_back(num); int index = n - 1; for(int 阅读全文
posted @ 2023-04-24 19:52 失控D大白兔 阅读(8) 评论(0) 推荐(0) 编辑
摘要: ###一. 买卖一次(简单) dp[i]表示第i天卖出时的最大值,可以用滚动变量优化 ``` class Solution { public: int maxProfit(vector& prices) { int n = prices.size(); vector dp(n+1); int min 阅读全文
posted @ 2023-04-24 19:17 失控D大白兔 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 给你一个字符串 s ,找出它的所有子串并按字典序排列,返回排在最后的那个子串 ###1. 暴力截取比较(超时) 记录最大字符位置,暴力截取比较 class Solution { public: string lastSubstring(string s) { map<char, vector<int 阅读全文
posted @ 2023-04-24 01:44 失控D大白兔 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数 n,计算所有小于等于 n 的非负整数中数字 1 出现的个数 ###1. 固定每一位找规律 class Solution { public: int countDigitOne(int n) { unsigned i = 1, ans = 0, befor = 0; //i表示记录到了第 阅读全文
posted @ 2023-04-24 00:10 失控D大白兔 阅读(32) 评论(0) 推荐(0) 编辑