随笔分类 -  LeetCode题解

上一页 1 2 3 4 5 6 7 ··· 17 下一页
摘要:1 /** 2 * Forward declaration of guess API. 3 * @param num your guess 4 * @return -1 if num is lower than the guess number 5 * 1 if num is higher than 阅读全文
posted @ 2020-04-26 19:26 Jinxiaobo0509 阅读(98) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 struct cmp 4 { 5 bool operator ()(vector<int> &a, const vector<int> &b) 6 { 7 // < :大顶堆 8 // > :小顶堆 9 return a[0]+a[1] > b[0]+b 阅读全文
posted @ 2020-04-26 19:00 Jinxiaobo0509 阅读(119) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 vector<int> findAnagrams(string s, string t) 5 { 6 unordered_map<char, int> need, window; 7 for (char c : t) need[c]+ 阅读全文
posted @ 2020-04-25 11:15 Jinxiaobo0509 阅读(121) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 // 判断 s 中是否存在 t 的排列 5 bool checkInclusion(string t, string s) 6 { 7 unordered_map<char, int> need, window; 8 for (cha 阅读全文
posted @ 2020-04-25 11:02 Jinxiaobo0509 阅读(134) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 string plusOne(string s, int j) // 将 s[j] 向上拨动一次 5 { 6 if(s[j] == '9') s[j] = '0'; 7 else s[j] += 1; 8 return s; 9 } 阅读全文
posted @ 2020-04-24 16:07 Jinxiaobo0509 阅读(169) 评论(0) 推荐(0)
摘要:1 class UF 2 { 3 public: 4 int count; // 记录连通分量个数 5 vector<int> parent; // 存储若干棵树 6 vector<int> size; // 记录树的“重量” 7 8 UF(int n) 9 { 10 count = n; 11 p 阅读全文
posted @ 2020-04-23 22:45 Jinxiaobo0509 阅读(222) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 int base = 1337; 4 5 int mypow(int a, int k) 6 { 7 if (k == 0) return 1; 8 a %= base; 9 10 if (k % 2 == 1) // k 是奇数 11 { 12 ret 阅读全文
posted @ 2020-04-23 14:47 Jinxiaobo0509 阅读(171) 评论(0) 推荐(0)
摘要:1 //最长上升子序列的变种 2 class Solution 3 { 4 public: 5 vector<int> largestDivisibleSubset(vector<int>& nums) 6 { 7 vector<int> ans;//保存结果 8 if(nums.size() == 阅读全文
posted @ 2020-04-23 10:08 Jinxiaobo0509 阅读(189) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 bool isPerfectSquare(int num) 5 { 6 if(num == 1) return true; 7 for(int i = 1;i <= num/2;i ++) 8 { 9 if((long long)i 阅读全文
posted @ 2020-04-22 23:31 Jinxiaobo0509 阅读(110) 评论(0) 推荐(0)
摘要:1 // 而贝祖定理告诉我们,ax+by=z 有解当且仅当z是x,y的最大公约数的倍数。 2 // 因此我们只需要找到x,y的最大公约数并判断z是否是它的倍数即可。 3 4 //纯粹的数学问题 5 class Solution 6 { 7 public: 8 bool canMeasureWater 阅读全文
posted @ 2020-04-22 23:20 Jinxiaobo0509 阅读(88) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int countNumbersWithUniqueDigits(int n) 5 { 6 if(n >= 11) return 8877691; 7 vector<int> nums(11); 8 int res = 0; 9 nu 阅读全文
posted @ 2020-04-22 23:01 Jinxiaobo0509 阅读(126) 评论(0) 推荐(0)
摘要:1 class Twitter 2 { 3 public: 4 unordered_map<int,priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>> u;//用户 -> (出现的次数,推文) 小根堆 阅读全文
posted @ 2020-04-22 22:29 Jinxiaobo0509 阅读(129) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 vector<int> intersect(vector<int>& nums1, vector<int>& nums2) 5 { 6 vector<int> res; 7 unordered_map<int,int> hash1,h 阅读全文
posted @ 2020-04-22 19:31 Jinxiaobo0509 阅读(96) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 vector<int> intersection(vector<int>& nums1, vector<int>& nums2) 5 { 6 vector<int> res; 7 unordered_map<int,int> hash 阅读全文
posted @ 2020-04-22 19:25 Jinxiaobo0509 阅读(99) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 vector<int> topKFrequent(vector<int>& nums, int k) 5 { 6 vector<int> res; 7 unordered_map<int,int> hash; 8 for(auto a 阅读全文
posted @ 2020-04-22 19:19 Jinxiaobo0509 阅读(98) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 unordered_set<char> hash = {'a','e','i','o','u','A','E','I','O','U'}; 4 public: 5 string reverseVowels(string s) 6 { 7 int n = 阅读全文
posted @ 2020-04-22 19:08 Jinxiaobo0509 阅读(122) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 void reverseString(vector<char>& s) 5 { 6 int n = s.size(); 7 for(int i = 0;i < n/2;i ++) swap(s[i],s[n - i - 1]); 8 阅读全文
posted @ 2020-04-22 18:57 Jinxiaobo0509 阅读(92) 评论(0) 推荐(0)
摘要:1 //以3来进行划分 2 class Solution 3 { 4 public: 5 int integerBreak(int n) 6 { 7 if(n <= 3) return n - 1; //必须切一刀 8 //n >= 5 2*(n-2) > n 3*(n-3) > n 且3*(n-3 阅读全文
posted @ 2020-04-22 18:53 Jinxiaobo0509 阅读(166) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 vector<int> countBits(int num) 5 { 6 vector<int> res; 7 for(int i = 0;i <= num;i ++) 8 { 9 int count = 0; 10 for(int 阅读全文
posted @ 2020-04-22 18:12 Jinxiaobo0509 阅读(90) 评论(0) 推荐(0)
摘要: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), 阅读全文
posted @ 2020-04-22 11:44 Jinxiaobo0509 阅读(101) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 17 下一页