摘要:
题目: 解答: 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 class Solution { 2 public: 3 4 vector<vector<string>> partition(string s) 5 { 6 vector<string> temp; 7 vector<vector<string>> result; 8 9 ge 阅读全文
posted @ 2020-05-16 12:54
梦醒潇湘
阅读(267)
评论(0)
推荐(0)
摘要:
题目: 解答: 先序遍历进行处理。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNod 阅读全文
posted @ 2020-05-16 12:36
梦醒潇湘
阅读(282)
评论(0)
推荐(0)