随笔分类 -  Leetcode

摘要:link class Solution { public: #define LL long long const int mod=1E9+7; int c[10015][15]; vector<int> waysToFillArray(vector<vector<int>>& queries) { 阅读全文
posted @ 2021-01-25 21:37 feibilun 阅读(86) 评论(0) 推荐(0)
摘要:link class Solution { public: struct State{ int mpos; int cpos; int turn; int win; State(int m, int c, int t, int w){ mpos=m; cpos=c; turn=t; win=w; } 阅读全文
posted @ 2021-01-18 12:16 feibilun 阅读(86) 评论(0) 推荐(0)
摘要:link 普通dp: class Solution { public: int n; int minimumTimeRequired(vector<int>& jobs, int k) { n=jobs.size(); vector<int> sum(1<<n); for(int i=1;i<(1< 阅读全文
posted @ 2021-01-11 18:44 feibilun 阅读(91) 评论(0) 推荐(0)
摘要:link class Solution { public: int boxDelivering(vector<vector<int>>& boxes, int portsCount, int maxBoxes, int maxWeight) { int n=boxes.size(); vector< 阅读全文
posted @ 2020-12-14 10:52 feibilun 阅读(233) 评论(0) 推荐(0)
摘要:link class Solution { public: int stoneGameVI(vector<int>& aliceValues, vector<int>& bobValues) { int n=aliceValues.size(); vector<int> sum(n); for(in 阅读全文
posted @ 2020-12-14 08:28 feibilun 阅读(125) 评论(0) 推荐(0)
摘要:link class Solution { public: int minMoves(vector<int>& nums, int limit) { int n=nums.size(); vector<int> diff(2*limit+2); for(int i=0;i<n/2;i++){ int 阅读全文
posted @ 2020-11-30 16:14 feibilun 阅读(100) 评论(0) 推荐(0)
摘要:link /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NUL 阅读全文
posted @ 2020-11-24 09:02 feibilun 阅读(86) 评论(0) 推荐(0)
摘要:link class Solution { public: int memo[5][5][7][7][1<<10]; int getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) { memset(me 阅读全文
posted @ 2020-11-16 09:36 feibilun 阅读(150) 评论(0) 推荐(0)
摘要:link class Solution { public: int n; int memo[50][1<<10]; bool canDistribute(vector<int>& nums, vector<int>& quantity) { vector<int> cnt(1001); n=quan 阅读全文
posted @ 2020-11-16 09:35 feibilun 阅读(136) 评论(0) 推荐(0)
摘要:link class Solution { public: int fa[10001]; vector<bool> areConnected(int n, int threshold, vector<vector<int>>& queries) { for(int i=1;i<=n;i++) fa[ 阅读全文
posted @ 2020-10-18 17:52 feibilun 阅读(106) 评论(0) 推荐(0)
摘要:link class Solution { public: #define LL long long unordered_map<int,LL> memo; int busRapidTransit(int target, int inc, int dec, vector<int>& jump, ve 阅读全文
posted @ 2020-09-15 21:07 feibilun 阅读(117) 评论(0) 推荐(0)
摘要:link class Solution { public: bool isTransformable(string s, string t) { vector<deque<int>> pos(10); for(int i=0;i<s.size();i++){ pos[s[i]-'0'].push_b 阅读全文
posted @ 2020-09-15 08:23 feibilun 阅读(87) 评论(0) 推荐(0)
摘要:link class Solution { public: #define LL long long const int mod=1E9+7; vector<vector<LL>> table; int numOfWays(vector<int>& nums) { int n=nums.size() 阅读全文
posted @ 2020-08-30 17:10 feibilun 阅读(272) 评论(0) 推荐(0)
摘要:link class Solution { public: int maxNonOverlapping(vector<int>& nums, int target) { unordered_map<int,int> pos; pos[0]=-1; int sum=0; int n=nums.size 阅读全文
posted @ 2020-08-10 10:44 feibilun 阅读(136) 评论(0) 推荐(0)
摘要:link class Solution { public: int longestAwesome(string s) { int n=s.size(); vector<int> dp(1<<10,n); int res=1; dp[0]=-1; int mask=0; for(int i=0;i<n 阅读全文
posted @ 2020-08-10 09:32 feibilun 阅读(155) 评论(0) 推荐(0)
摘要:link 随着i增加,缺失的个数非减,在i处缺失的个数为arr[i]-(i+1).二分找到第一个缺失个数大于等于k的位置left, 则left-1处缺失的个数<k。left-1处缺失的个数为arr[left-1]-left, 还差k-arr[left-1]+left个,则答案是k+left. cla 阅读全文
posted @ 2020-08-09 20:53 feibilun 阅读(130) 评论(0) 推荐(0)
摘要:link class Solution { public: struct TrieNode{ TrieNode* children[26]; int id; TrieNode(){ id=-1; for(int i=0;i<26;i++) children[i]=nullptr; } }; Trie 阅读全文
posted @ 2020-08-06 11:14 feibilun 阅读(60) 评论(0) 推荐(0)
摘要:link prove: @interviewrecipes https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid/discuss/768076/Min-Adjacent-Swaps-to-Sort-the-array 阅读全文
posted @ 2020-08-04 11:05 feibilun 阅读(166) 评论(0) 推荐(0)
摘要:link class Solution { public: vector<string> maxNumOfSubstrings(string s) { int n=s.size(); vector<int> left(26,n); vector<int> right(26,-1); for(int 阅读全文
posted @ 2020-07-19 22:18 feibilun 阅读(135) 评论(0) 推荐(0)
摘要:link class Solution { public: int n; double eps=1E-6; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; double getMinDistSum(vector<vector<int>> 阅读全文
posted @ 2020-07-12 17:35 feibilun 阅读(196) 评论(0) 推荐(0)