摘要:
题目: 解答: 先排序,然后设定返回值为最大,用双指针求得结果。 1 class Solution { 2 public: 3 int smallestDifference(vector<int>& a, vector<int>& b) 4 { 5 sort(a.begin(),a.end()); 阅读全文
posted @ 2020-05-05 19:11
梦醒潇湘
阅读(195)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 class Solution { 2 public: 3 void merge(vector<int>& A, int m, vector<int>& B, int n) 4 { 5 int len1 = m - 1; 6 int len2 = n - 1; 7 int len 阅读全文
posted @ 2020-05-05 18:55
梦醒潇湘
阅读(177)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 class Solution { 2 public: 3 vector<vector<int>> res; 4 5 vector<vector<int>> subsets(vector<int>& nums) 6 { 7 // 记录走过的路径 8 vector<int> trac 阅读全文
posted @ 2020-05-05 18:45
梦醒潇湘
阅读(161)
评论(0)
推荐(0)
摘要:
题目: 解答: 方法一:会超时间 1 class Solution { 2 public: 3 void rotate(vector<vector<int>>& matrix) 4 { 5 // 思路是: 转置 + 反转每一行 6 7 int len = matrix.size(); 8 9 // 阅读全文
posted @ 2020-05-05 18:40
梦醒潇湘
阅读(173)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 class Solution { 2 public: 3 bool isUnique(string astr) 4 { 5 int mark = 0; 6 for (int i = 0; i < astr.size(); i++) 7 { 8 int move_bit = ast 阅读全文
posted @ 2020-05-05 18:04
梦醒潇湘
阅读(130)
评论(0)
推荐(0)
摘要:
题目: 解答: (1)首先计算数组 A 中所有数字总和 sum; (2)遍历数组 A 查找和为 sum / 3的子数组个数; (3)如果找到了三个这样的子数组则返回 true (4)找不到三个就返回 false; 1 class Solution { 2 public: 3 bool canThre 阅读全文
posted @ 2020-05-05 17:52
梦醒潇湘
阅读(262)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 class Solution { 2 public: 3 vector<vector<int>> transpose(vector<vector<int>>& A) 4 { 5 int ro = A.size(); 6 int co = A[0].size(); 7 8 vect 阅读全文
posted @ 2020-05-05 17:48
梦醒潇湘
阅读(130)
评论(0)
推荐(0)
摘要:
题目: 解答: 动态规划。 1 class Solution { 2 public: 3 int findLength(vector<int>& A, vector<int>& B) 4 { 5 int ans = 0; 6 vector<vector<int>> memo(A.size() + 1 阅读全文
posted @ 2020-05-05 17:30
梦醒潇湘
阅读(196)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 class Solution { 2 public: 3 int numSubarrayProductLessThanK(vector<int>& nums, int k) 4 { 5 if (k <= 1) 6 { 7 return 0; 8 } 9 10 int prod = 阅读全文
posted @ 2020-05-05 17:26
梦醒潇湘
阅读(172)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 先将数每一位拆成数组2,若数组为非升序序列,则直接返回原数即可3,否则,就找到数组中第一次出现升序的位置,从该位置往后找到最后一个最大值max_val及其下标max_ind4,从数组头开始找第一个比max_val小的数的下标i,交换i与max_ind位置的数即可 1 class 阅读全文
posted @ 2020-05-05 17:24
梦醒潇湘
阅读(170)
评论(0)
推荐(0)

浙公网安备 33010602011771号