上一页 1 2 3 4 5 6 7 8 9 ··· 45 下一页
摘要: 118. 杨辉三角 二维数组 class Solution { public: vector<vector<int>> generate(int numRows) { vector<vector<int>>a; if(numRows==0) { return a; } if(numRows==1) 阅读全文
posted @ 2020-06-22 12:19 branna 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 48. 旋转图像 class Solution { public: void rotate(vector<vector<int>>& matrix) { for(int i=0;i<matrix.size()/2;i++)//将行看做一个整体,逆序存放 { swap(matrix[i],matrix 阅读全文
posted @ 2020-06-21 22:14 branna 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 560. 和为K的子数组 暴力O(n^2) 利用前缀和做差有多少组差为k class Solution { public: int subarraySum(vector<int>& nums, int k) { int sum[nums.size()+10]; int ops=0; sum[ops] 阅读全文
posted @ 2020-06-21 16:36 branna 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 75. 颜色分类 根据题意提示,用计数排序扫描每个颜色的个数,然后重新往数组里填充012的个数即可,一趟扫描 class Solution { public: void sortColors(vector<int>& nums) { map<int,int>mp; for(int i=0;i<num 阅读全文
posted @ 2020-06-21 13:33 branna 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 670. 最大交换 贪心O(n): class Solution { public: int maximumSwap(int num) { string s=to_string(num); map<char,int>mp; for(int i=0;i<s.length();i++) mp[s[i]] 阅读全文
posted @ 2020-06-19 17:20 branna 阅读(163) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 45 下一页