1 2 3 4 5 ··· 38 下一页
摘要: 题目: 解答: 本题的简单解法: 1 class Solution { 2 public: 3 vector<int> printNumbers(int n) 4 { 5 vector<int> res; 6 7 if (n == 0) 8 { 9 return res; 10 } 11 12 // 阅读全文
posted @ 2020-05-29 11:23 梦醒潇湘 阅读(154) 评论(0) 推荐(0)
摘要: 题目: 解答: 思路: 一次遍历找到最大的数max1和第二大的数max2,然后看看最大的数是不是大于等于第二大的数的两倍。如果是的话那么肯定满足最大数max1大于等于数组中其他数组的两倍了。 1 class Solution { 2 public: 3 int dominantIndex(vecto 阅读全文
posted @ 2020-05-20 11:21 梦醒潇湘 阅读(191) 评论(0) 推荐(0)
摘要: 题目: 解答: sumleft + num[i] + sumright = totalsum sumleft = sumright > 2 * sumleft = totalsum - num[i] 1 class Solution { 2 public: 3 4 // sumleft + nums 阅读全文
posted @ 2020-05-20 11:19 梦醒潇湘 阅读(443) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 bool isPowerOfThree(int n) 4 { 5 if (n < 1) 6 { 7 return false; 8 } 9 10 while (n % 3 == 0) 11 { 12 n /= 3; 13 阅读全文
posted @ 2020-05-16 14:14 梦醒潇湘 阅读(301) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 int hammingWeight(uint32_t n) 4 { 5 int res = 0; 6 while(n != 0) 7 { 8 res += n & 1; 9 n >>= 1; 10 } 11 return 阅读全文
posted @ 2020-05-16 14:00 梦醒潇湘 阅读(272) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 uint32_t reverseBits(uint32_t n) 4 { 5 int res = 0; 6 for (int i = 0; i < 32; i++) 7 { 8 res = (res << 1) + (n 阅读全文
posted @ 2020-05-16 13:51 梦醒潇湘 阅读(301) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 bool increasingTriplet(vector<int>& nums) 4 { 5 int len = nums.size(); 6 7 if (len < 3) 8 { 9 return false; 10 阅读全文
posted @ 2020-05-16 13:35 梦醒潇湘 阅读(220) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 vector<int> intersect(vector<int>& nums1, vector<int>& nums2) 4 { 5 if (nums1.size() > nums2.size()) 6 { 7 retu 阅读全文
posted @ 2020-05-16 13:30 梦醒潇湘 阅读(229) 评论(0) 推荐(0)
摘要: 题目: 解答: 一般来说,对于一个问题我通常会给出两种以上的解法,但是对于洗牌问题,Fisher-Yates洗牌算法即是通俗解法,同时也是渐进最优的解法。 1 class Solution { 2 public: 3 4 vector<int> nums; 5 vector<int> copy; 6 阅读全文
posted @ 2020-05-16 13:18 梦醒潇湘 阅读(211) 评论(0) 推荐(0)
摘要: 题目: 解答: 说实话,我自己是没有想出来这道题要用到动态规划的思想,而且一开始也没有理解这种方法。 具体方法: (1)本题的子问题设为从字符串 s 的前 i 个元素中能否切分出字典 wordDict 里面的单词。因为考虑到空字符串的问题,我们将用于记录子问题信息的vector定义为 len+1 大 阅读全文
posted @ 2020-05-16 13:00 梦醒潇湘 阅读(554) 评论(0) 推荐(0)
1 2 3 4 5 ··· 38 下一页