摘要:
题目: 解答: 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 阅读全文
posted @ 2020-05-09 19:56
梦醒潇湘
阅读(155)
评论(0)
推荐(0)
摘要:
题目: 解答: 思路描述: 这个就可以先排一下序,然后计算出来 0 的个数 num1,以及需要多少张牌才能够连续,比如: 1 2 4 需要一张牌才能连续,如果数目不大于 num1,那么就是顺子。其中注意出现相同的牌也不是顺子! 1 class Solution { 2 public: 3 bool 阅读全文
posted @ 2020-05-09 19:53
梦醒潇湘
阅读(188)
评论(0)
推荐(0)
摘要:
题目: 解答: 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( 阅读全文
posted @ 2020-05-09 19:49
梦醒潇湘
阅读(126)
评论(0)
推荐(0)
摘要:
题目: 解答: 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 阅读全文
posted @ 2020-05-09 19:45
梦醒潇湘
阅读(139)
评论(0)
推荐(0)
摘要:
题目: 解答: 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; 阅读全文
posted @ 2020-05-09 19:42
梦醒潇湘
阅读(148)
评论(0)
推荐(0)
摘要:
题目: 解答: 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 阅读全文
posted @ 2020-05-09 19:36
梦醒潇湘
阅读(146)
评论(0)
推荐(0)
摘要:
题目: 解答: 方法一: 两次反转,先反转每个单词,再反转每个句子。 方法二: 1 class Solution { 2 public: 3 string reverseWords(string s) 4 { 5 if(s.empty()) 6 { 7 return s; 8 } 9 10 int 阅读全文
posted @ 2020-05-09 19:35
梦醒潇湘
阅读(172)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 class Solution { 2 public: 3 vector<vector<int>> findContinuousSequence(int target) 4 { 5 int i = 1; // 滑动窗口的左边界 6 int j = 1; // 滑动窗口的右边界 7 阅读全文
posted @ 2020-05-09 19:31
梦醒潇湘
阅读(149)
评论(0)
推荐(0)
摘要:
题目: 解答: 1 class Solution { 2 public: 3 vector<int> twoSum(vector<int>& nums, int target) 4 { 5 // vector<int> res; 6 if (nums.size() <= 1) 7 { 8 retur 阅读全文
posted @ 2020-05-09 19:28
梦醒潇湘
阅读(134)
评论(0)
推荐(0)
摘要:
题目: 解答: 方法一:哈希 class Solution { public: int singleNumber(std::vector<int> &nums) { if (nums.empty()) { return 0; } // 哈希表存储数和其出现次数 std::unordered_map< 阅读全文
posted @ 2020-05-09 19:24
梦醒潇湘
阅读(201)
评论(0)
推荐(0)