码迷,mamicode.com
首页 >  
搜索关键字:解答    ( 4882个结果
面试题48. 最长不含重复字符的子字符串
题目: 解答: 思路:滑动窗口。 我们可以使用哈希表记录每个字符的下一个索引,然后尽量向右移动尾指针来拓展窗口,并更新窗口的最大长度。如果尾指针指向的元素重复,则将头指针直接移动到窗口中重复元素的右侧。 1 class Solution { 2 public: 3 int lengthOfLonge ...
分类:其他好文   时间:2020-05-09 23:15:47    阅读次数:56
面试题58 - II. 左旋转字符串
题目: 解答: 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
面试题66. 构建乘积数组
题目: 解答: 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
面试题59 - II. 队列的最大值
题目: 解答: 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
面试题57 - II. 和为s的连续正数序列
题目: 解答: 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
面试题58 - I. 翻转单词顺序
题目: 解答: 方法一: 两次反转,先反转每个单词,再反转每个句子。 方法二: 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
面试题61. 扑克牌中的顺子
题目: 解答: 思路描述: 这个就可以先排一下序,然后计算出来 0 的个数 num1,以及需要多少张牌才能够连续,比如: 1 2 4 需要一张牌才能连续,如果数目不大于 num1,那么就是顺子。其中注意出现相同的牌也不是顺子! 1 class Solution { 2 public: 3 bool ...
分类:其他好文   时间:2020-05-09 21:15:42    阅读次数:72
面试题58 - II. 左旋转字符串
题目: 解答: 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
面试题64. 求1+2+…+n
题目: 解答: 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
面试题63. 股票的最大利润
题目: 解答: 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
4882条   上一页 1 ... 21 22 23 24 25 ... 489 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!