题目: 解答: 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
题目: 解答: 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
题目: 解答: 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
题目: 解答: 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
题目: 解答: 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
题目: 解答: 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
题目: 解答: 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
题目: 解答: 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
题目: 解答: 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
题目: 解答: 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