题目: 解答: 思路:滑动窗口。 我们可以使用哈希表记录每个字符的下一个索引,然后尽量向右移动尾指针来拓展窗口,并更新窗口的最大长度。如果尾指针指向的元素重复,则将头指针直接移动到窗口中重复元素的右侧。 1 class Solution { 2 public: 3 int lengthOfLonge ...
分类:
其他好文 时间:
2020-05-09 23:15:47
阅读次数:
56
题目: 解答: 1 class Solution { 2 public: 3 int reverse_string(string& s, int start, int end) 4 { 5 for (int i = start; i <= (start + end) / 2; i++) 6 { 7 ...
分类:
其他好文 时间:
2020-05-09 21:44:58
阅读次数:
67
题目: 解答: 1 class Solution { 2 public: 3 vector<int> constructArr(vector<int>& a) 、 4 { 5 int n = a.size(); 6 vector<int> ret(n, 1); 7 8 int left = 1; 9 ...
分类:
编程语言 时间:
2020-05-09 21:41:37
阅读次数:
74
题目: 解答: 1 class MaxQueue { 2 queue<int> q; 3 deque<int> d; 4 public: 5 MaxQueue() { 6 } 7 8 int max_value() 9 { 10 if (d.empty()) 11 return -1; 12 ret ...
分类:
其他好文 时间:
2020-05-09 21:39:21
阅读次数:
57
题目: 解答: 1 class Solution { 2 public: 3 vector<vector<int>> findContinuousSequence(int target) 4 { 5 int i = 1; // 滑动窗口的左边界 6 int j = 1; // 滑动窗口的右边界 7 ...
分类:
其他好文 时间:
2020-05-09 21:30:07
阅读次数:
59
题目: 解答: 方法一: 两次反转,先反转每个单词,再反转每个句子。 方法二: 1 class Solution { 2 public: 3 string reverseWords(string s) 4 { 5 if(s.empty()) 6 { 7 return s; 8 } 9 10 int ...
分类:
其他好文 时间:
2020-05-09 21:16:30
阅读次数:
57
题目: 解答: 思路描述: 这个就可以先排一下序,然后计算出来 0 的个数 num1,以及需要多少张牌才能够连续,比如: 1 2 4 需要一张牌才能连续,如果数目不大于 num1,那么就是顺子。其中注意出现相同的牌也不是顺子! 1 class Solution { 2 public: 3 bool ...
分类:
其他好文 时间:
2020-05-09 21:15:42
阅读次数:
72
题目: 解答: 1 class Solution { 2 public: 3 string reverseLeftWords(string s, int n) 4 { 5 reversestr(s, 0, n); 6 reversestr(s, n, s.size()); 7 reversestr( ...
分类:
其他好文 时间:
2020-05-09 21:07:44
阅读次数:
52
题目: 解答: 1 class Solution { 2 public: 3 int sumNums(int n) 4 { 5 if(n == 1) 6 { 7 return 1; 8 } 9 n += sumNums(n - 1); 10 return n; 11 } 12 }; ...
分类:
其他好文 时间:
2020-05-09 21:02:46
阅读次数:
68
题目: 解答: 1 class Solution { 2 public: 3 int maxProfit(vector<int>& prices) 4 { 5 int cost = INT_MAX; 6 int profit = 0; 7 for (int price: prices) 8 { 9 ...
分类:
其他好文 时间:
2020-05-09 20:50:03
阅读次数:
59