Loading

上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 75 下一页
摘要: 思路 方法:维护一个单调的双端队列 1 class MaxQueue { 2 private: 3 queue<int> A; 4 deque<int> B; 5 public: 6 MaxQueue() { 7 8 } 9 10 int max_value() { 11 if(B.empty()) 阅读全文
posted @ 2020-11-14 14:21 拾月凄辰 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 思路 方法一:暴力法 遍历每一个数nums[i],之后在[i, i+k]中顺序寻找最大值。 时间复杂度:O(k*n) 1 class Solution { 2 public: 3 vector<int> maxSlidingWindow(vector<int>& nums, int k) { 4 i 阅读全文
posted @ 2020-11-14 11:41 拾月凄辰 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 思路 方法一:库函数rotate() 1 class Solution { 2 public: 3 string reverseLeftWords(string s, int n) { 4 rotate(s.begin(), s.begin()+n, s.end()); 5 return s; 6 阅读全文
posted @ 2020-11-14 11:07 拾月凄辰 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 思路 方法一:分割 + 倒序 时间复杂度:O(n),n为s的长度。 1 class Solution { 2 public: 3 string reverseWords(string s) { 4 string t = ""; 5 stack<string> strStack; 6 for(int 阅读全文
posted @ 2020-11-14 10:29 拾月凄辰 阅读(73) 评论(0) 推荐(0) 编辑
摘要: 思路 方法一:枚举 + 暴力 1 class Solution { 2 public: 3 vector<vector<int>> findContinuousSequence(int target) { 4 vector<vector<int>> res; 5 for(int i = 1; i < 阅读全文
posted @ 2020-11-14 09:41 拾月凄辰 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 思路 方法一:二分 遍历每个数字num,然后再在后面的数字中使用二分查找target-num。 复杂度分析 时间复杂度:O(nlogn) 空间复杂度:O(1) 1 class Solution { 2 public: 3 vector<int> twoSum(vector<int>& nums, i 阅读全文
posted @ 2020-11-13 20:23 拾月凄辰 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 思路 方法:位运算 遍历统计 1 class Solution { 2 private: 3 int cnt[32] = {0}; 4 public: 5 int singleNumber(vector<int>& nums) { 6 for(int num: nums) { 7 for(int i 阅读全文
posted @ 2020-11-13 20:02 拾月凄辰 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 思路 方法:分组异或 1 class Solution { 2 public: 3 vector<int> singleNumbers(vector<int>& nums) { 4 int res = 0; 5 for(int &num: nums) { 6 res ^= num; 7 } 8 9 阅读全文
posted @ 2020-11-13 17:38 拾月凄辰 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 思路 方法一:暴力递归法 (自顶向下的递归) 使用递归编写一个求高度的函数,之后使用先序遍历每个结点,判断左右子树的高度差是否满足要求。 这种方法每次判断一个结点都需要使用递归先求出其左右子树的高度,比如下面这棵树,判断1的时候,使用递归求了2,3, 4的高度,判断2的时候,又递归求了3,4,的高度 阅读全文
posted @ 2020-11-10 15:20 拾月凄辰 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 思路 方法:递归 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) 阅读全文
posted @ 2020-11-10 14:43 拾月凄辰 阅读(64) 评论(0) 推荐(0) 编辑
上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 75 下一页