码迷,mamicode.com
首页 >  
搜索关键字:解答    ( 4882个结果
面试题62. 圆圈中最后剩下的数字
题目: 解答: 1 class Solution { 2 int f(int n, int m) 3 { 4 if (n == 1) 5 { 6 return 0; 7 } 8 int x = f(n - 1, m); 9 return (m + x) % n; 10 } 11 public: 12 ...
分类:其他好文   时间:2020-05-09 20:43:10    阅读次数:58
面试题59 - I. 滑动窗口的最大值
题目: 解答: 1 class Solution { 2 public: 3 vector<int> maxSlidingWindow(vector<int>& nums, int k) 4 { 5 if(nums.size() == 0 || k == 1) 6 { 7 return nums; ...
分类:其他好文   时间:2020-05-09 20:38:37    阅读次数:62
面试题36. 二叉搜索树与双向链表
题目: 解答: 1 // 中序遍历即可。只需要记录一个pre指针即可。 2 3 4 class Solution { 5 public: 6 TreeNode* Convert(TreeNode* pRootOfTree) 7 { 8 if(pRootOfTree == nullptr) 9 { 1 ...
分类:其他好文   时间:2020-05-09 17:05:24    阅读次数:63
面试题38. 字符串的排列(全排列)
题目: 解答: 1 class Solution { 2 public: 3 vector<string> permutation(string str) 4 { 5 vector<string> result; 6 if(str.empty()) 7 { 8 return result; 9 } ...
分类:其他好文   时间:2020-05-09 17:02:54    阅读次数:69
面试题39. 数组中出现次数超过一半的数字
题目: 解答: 1 class Solution { 2 public: 3 int majorityElement(vector<int>& nums) 4 { 5 int x = 0; 6 int votes = 0; 7 for(int num : nums) 8 { 9 if(votes = ...
分类:编程语言   时间:2020-05-09 16:54:18    阅读次数:60
面试题40. 最小的k个数
题目: 解答: 1 class Solution { 2 public: 3 vector<int> getLeastNumbers(vector<int>& arr, int k) 4 { 5 vector<int> res; 6 priority_queue<int> q; 7 for (int ...
分类:其他好文   时间:2020-05-09 16:45:57    阅读次数:52
面试题37. 序列化二叉树
题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : ...
分类:其他好文   时间:2020-05-09 16:40:04    阅读次数:47
面试题19. 正则表达式匹配
题目: 解答: 1 class Solution { 2 public: 3 bool isMatch(string s, string p) 4 { 5 s=" "+s;//防止该案例:""\n"c*" 6 p=" "+p; 7 8 int m = s.size(); 9 int n = p.si ...
分类:其他好文   时间:2020-05-09 14:19:42    阅读次数:61
面试题20. 表示数值的字符串
题目: 解答: 1)先去除字符串首尾的空格2)然后根据e划分指数和底数3)判断指数和底数是否合法即可 1 class Solution { 2 public: 3 bool isNumber(string s) { 4 //1、从首尾寻找s中不为空格首尾位置,也就是去除首尾空格 5 int i=s. ...
分类:其他好文   时间:2020-05-09 14:17:22    阅读次数:52
面试题07. 根据前序和中序重建二叉树
题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : ...
分类:其他好文   时间:2020-05-09 13:08:27    阅读次数:76
4882条   上一页 1 ... 22 23 24 25 26 ... 489 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!