摘要: 228. 汇总区间 分类: 数组 简单题,但是边界条件挺细节,特别是c++,还要额外注意int的边界,不然 nums[i] == nums[i-1] + 1会overflow class Solution { public: vector<string> summaryRanges(vector<i 阅读全文
posted @ 2021-01-10 12:32 vwmin 阅读(42) 评论(0) 推荐(0)
摘要: 123. 买卖股票的最佳时机 III 分类: dp 我以为是动态规划之实际上是暴力 class Solution { public: int maxProfit(vector<int>& prices) { int n = prices.size(); vector<vector<int>> dp( 阅读全文
posted @ 2021-01-09 12:07 vwmin 阅读(48) 评论(0) 推荐(0)
摘要: 189. 旋转数组 分类: 数组 数组循环移位经典题 class Solution { // 翻转数组 public: void reverse(vector<int>& nums, int i, int j){ int t; while(i < j){ t = nums[i]; nums[i++] 阅读全文
posted @ 2021-01-08 11:46 vwmin 阅读(45) 评论(0) 推荐(0)
摘要: 分类: 图 并查集 class Solution { public: int root(int* u, int j){ //找到j的集合根 while(j != u[j]) j = u[j]; return j; } void combine(int* u, int i, int j){ //把j接 阅读全文
posted @ 2021-01-07 11:41 vwmin 阅读(66) 评论(0) 推荐(0)