随笔分类 - LeetCode题解
摘要:1 class Solution 2 { 3 public: 4 int rob(vector<int>& nums) 5 { 6 if(nums.size() == 0) return 0; 7 if(nums.size() == 1) return nums[0]; 8 if(nums.size
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 // 前i个字符串构成 == 前i-1个字符串构成(只有一个字符1-9) 5 // +前i-2个字符串构成(只有两个字符10-26) 6 int numDecodings(string s) 7 { 8 int n = s.size(
        阅读全文
                
摘要:1 // 统计个数,相同位置相同数字的个数 >A的个数 2 // 不同位置相同数字的个数 >B的个数 3 class Solution 4 { 5 public: 6 string getHint(string secret, string guess) 7 { 8 int n = secret.s
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 bool canWinNim(int n) 5 { 6 //如果不是4的倍数,必赢 7 //如果是4的倍数,必输 8 return n % 4 != 0; 9 } 10 };
        阅读全文
                
摘要:1 class Solution 2 { 3 vector<string> res; 4 void spilt(string s,char c,vector<string> &res) 5 { 6 istringstream iss(s); 7 string temp; 8 while(getlin
        阅读全文
                
摘要:1 class Solution 2 { 3 int dx[8] = {1,1,0,-1,-1,-1,0,1}; 4 int dy[8] = {0,1,1,1,0,-1,-1,-1}; 5 public: 6 void gameOfLife(vector<vector<int>>& board) 7
        阅读全文
                
摘要:1 /* 2 * Below is the interface for Iterator, which is already defined for you. 3 * **DO NOT** modify the interface for Iterator. 4 * 5 * class Iterat
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 void moveZeroes(vector<int>& nums) 5 { 6 int n = nums.size(); 7 int begin = 0; 8 for(int i = 0;i < n;i ++) 9 { 10 if(
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 int numSquares(int n) 5 { 6 queue<pair<int,int>> Q; 7 Q.push(make_pair(n,0)); 8 vector<bool> visit(n+1,false); 9 //层序
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 int hIndex(vector<int>& nums) 5 { 6 sort(nums.begin(),nums.end()); 7 int l = 0,r = nums.size(); 8 while(l < r) 9 { 10
        阅读全文
                
摘要:1 //[3,0,1] + [0,1,2,3] = [0,0,1,1,2,3,3] ——> 求异或 2 class Solution 3 { 4 public: 5 int missingNumber(vector<int>& nums) 6 { 7 int n = nums.size(); 8 i
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 bool isUgly(int num) 5 { 6 if (num == 0) return false; 7 while (num % 2 == 0) num /= 2; 8 while (num % 3 == 0) num /=
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 vector<int> singleNumber(vector<int>& nums) 5 { 6 int diff = 0; 7 vector<int> res(2,0); 8 for (int num : nums) diff ^
        阅读全文
                
摘要:1 //很简单 2 class Solution 3 { 4 public: 5 int addDigits(int num) 6 { 7 while(num > 9) 8 { 9 int temp = 0; 10 while(num) 11 { 12 temp += num % 10; 13 nu
        阅读全文
                
摘要:1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x),
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 bool isAnagram(string s, string t) 5 { 6 unordered_map<char,int> hash_s,hash_t; 7 for(auto a : s) hash_s[a] ++; 8 for
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 vector<int> diffWaysToCompute(string input) 5 { 6 vector<int> res; 7 for(int i=0; i<input.size(); i++) 8 { 9 if(input
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 bool searchMatrix(vector<vector<int>>& matrix, int target) 5 { 6 if(matrix.empty() || matrix[0].empty()) return false
        阅读全文
                
摘要:1 class Solution 2 { 3 public: 4 vector<int> productExceptSelf(vector<int>& nums) 5 { 6 int n = nums.size(); 7 vector<int> A(n,1),B(n,1); 8 vector<int
        阅读全文
                
摘要:1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x),
        阅读全文
                
                    
                
浙公网安备 33010602011771号