- 博客(39)
- 收藏
- 关注
原创 No.175 - LeetCode1306
class Solution {public: bool dfs(vector<int>& ans,vector<int>& arr,int now){ if(ans[now] != 0) return false; ans[now] = 1; if(arr[now] == 0) return tru...
2019-12-31 21:32:57 162
原创 No.174 - LeetCode1305 - 合并两个搜索树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...
2019-12-31 21:24:05 204
原创 No.173 - LeetCode1304
class Solution {public: vector<int> sumZero(int n) { vector<int> ans(n,0); int cnt = 0; int key = 2000; for(int i=0;i<n/2;i++){ ans[cnt+...
2019-12-31 21:08:24 149
原创 No.172 - LeetCode1301
class Solution {public: vector<int> pathsWithMaxScore(vector<string>& board) { int N = board.size(); int M = board[0].length(); const long long mod = 10000...
2019-12-31 20:42:07 129
原创 No.171 - LeetCode1302
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...
2019-12-31 20:14:07 190
原创 No.170 - LeetCode1300
class Solution {public: int findBestValue(vector<int>& arr, int target) { int N = arr.size(); sort(arr.begin(),arr.end()); int ans = 1; int diff = abs(an...
2019-12-31 20:07:46 108
原创 No.169 - LeetCode1299
class Solution {public: vector<int> replaceElements(vector<int>& arr) { int N = arr.size(); vector<int> mx(N,0); mx[N-1] = -1; for(int i=N-2;...
2019-12-31 19:42:27 137
原创 No.168 - LeetCode1109 - 扫描线 - 一种很实用的算法
class Solution {public: vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) { vector<int> num(n+1,0); for(int i=0;i<bookings.size()...
2019-12-27 21:21:59 345
原创 No.167 - LeetCode1206
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...
2019-12-27 21:07:50 154
原创 No.166 - LeetCode1296
class Solution {public: bool isPossibleDivide(vector<int>& nums, int k) { int N = nums.size(); if( N % k != 0) return false; sort(nums.begin(),nums.end()); ...
2019-12-27 20:48:55 126
原创 No.165 - Codeforces-Contest-1282 - B
n个物品,每个物品对应价格。有种优惠,买物品A可以附赠价值小于A的k-1件商品则,现有p数量钱,最多买几件物品?原问题:优惠必须选k-1件赠品,多和少都不可以思路:k间隔枚举,再在从小价值物品里面挑#include<cstdio>#include<cstring>#include<algorithm>#include<cstring>...
2019-12-25 00:41:43 142
原创 python:类成员函数
python类成员函数分三种:\red{python类成员函数分三种:}python类成员函数分三种:1,不带装饰器的成员函数:\orange{1,不带装饰器的成员函数:}1,不带装饰器的成员函数:此类函数是类实例的成员函数,第一个参数必须是self,只有在类实例化后才能调用。2,带@classmethod装饰的成员函数:\orange{2,带@classmethod装饰的成员函数:}2,带...
2019-12-24 09:45:31 1054
原创 No.164 - LeetCode1190 - 括号总是离不开下标栈
class Solution {public: string reverseParentheses(string s) { stack<int> loc; for(int i=0;i<s.length();i++){ if(s[i] == '(') loc.push(i); else if(...
2019-12-17 23:32:40 162
原创 No.163 - LeetCode171
class Solution {public: int titleToNumber(string s) { int ans = 0; long long base = 1; for(int i=s.length()-1;i>=0;i--){ ans += (s[i] - 'A' + 1)*base; ...
2019-12-17 00:28:13 170
原创 No.162 - LeetCode792 - 字符串子序列匹配(下标挂链二分)
class Solution {public: int bsearch(int L,int R,vector<int>& V,int key){ //printf("<%d %d %d>\n",L,R,key); if(L+1>=R) return R; int mid = (L+R)/2; ...
2019-12-17 00:23:09 240
原创 No.161 - leetCode1292
class Solution {public: int maxSideLength(vector<vector<int>>& mat, int threshold) { int N = mat.size(); int M = mat[0].size(); vector<vector<int>...
2019-12-15 20:48:16 174
原创 No.160 - LeetCode1291
class Solution {public: int getNum(int i,int j){ if(i+j>10) return -1; int ans = 0; for(int k=0;k<i;k++){ ans *= 10; ans += j++; } ...
2019-12-15 20:20:50 94
原创 No.159 - LeetCode1290
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: int getDecim...
2019-12-15 20:12:16 158
原创 No.158 - LeetCode166 - 分数变小数(经典)- Fraction to Recurring Decimal
总结一下:很多边界问题,有些难处理。处理负数处理INT_MIN溢出无限循环的起始位置class Solution {public: string fractionToDecimal(int numerator, int denominator) { long long N = numerator; long long D = denomina...
2019-12-15 00:41:38 147
原创 No.157 - LeetCode? - Minimum Falling Path Sum II
class Solution {public: int minFallingPathSum(vector<vector<int>>& arr) { int N = arr.size(); int M = arr[0].size(); vector<vector<int>> dp(N+1...
2019-12-14 23:52:45 133
原创 No.156 - LeetCode? - Iterator for Combination
class CombinationIterator {public: string str; long long status; long long nextstatus; int N; // 整体长度 int L; // 组合长度 bool Dohasnext; bool lastflag; bool firsttime; ...
2019-12-14 23:51:52 114
原创 No.155 - LeetCode? - Remove Covered Intervals
class Solution {public: bool judge(int a,int b,int c,int d){ if(a <= c && b >= d) return true; return false; } int removeCoveredIntervals(vector<vector<...
2019-12-14 23:51:02 101
原创 No.154 - LeetCode? - Element Appearing More Than 25% In Sorted Array
class Solution {public: int findSpecialInteger(vector<int>& arr) { int N = arr.size(); map<int,int> mp; for(int i=0;i<N;i++){ mp[arr[i]]++;...
2019-12-14 23:50:05 129
原创 No.153 - LeetCode153 - 最远正序对
对于序对,最好的办法就是排序。统计数量用归并统计最值用单调type node struct{ Val int Loc int}type nodes []nodefunc (s nodes)Len() int { return len(s)}func (s nodes)Less(i,j int) bool { if s[i].Val == s[j...
2019-12-13 23:58:06 194
原创 No.152 - LeetCode938
func dfs(now *TreeNode, L int,R int, p *int) { if now.Left != nil && now.Val >= L { dfs(now.Left,L,R,p) } if now.Right != nil && now.Val <= R { dfs(no...
2019-12-13 01:17:29 100
原创 No.151 - LeetCode438
func judge(mp [26]int) bool{ for i:=0;i<len(mp);i++{ if mp[i] != 0{ return false } } return true}func findAnagrams(s string, p string) []int { if len(...
2019-12-11 23:48:22 68
原创 No.150 - LeetCode697
class Solution {public: int findShortestSubArray(vector<int>& nums) { map<int,pair<int,int>> mp; int mx = 0; int ans = 0; for(int i=0;i<nu...
2019-12-11 00:40:15 68
原创 No.149 - LeetCode560
func subarraySum(nums []int, k int) int { mp := make(map[int]int) ans := 0 sum := 0 mp[0] = 1 for i:=0;i<len(nums);i++{ sum += nums[i] ans += mp[sum - k] ...
2019-12-10 23:59:48 79
原创 No.148 - LeetCode771
func numJewelsInStones(J string, S string) int { var mp = make(map[byte]bool) ans := 0 for i:=0 ; i<len(J); i++{ mp[J[i]] = true } for i:=0 ; i<len(S); i++{ i...
2019-12-10 00:00:07 67
原创 No.147 - LeetCode1108
func defangIPaddr(address string) string { var ans string for i:=0;i<len(address);i++{ if address[i] != '.'{ ans += string(address[i]) }else{ ans += ...
2019-12-09 23:54:18 67
原创 No.146 - LeetCode859
func buddyStrings(A string, B string) bool { if len(A) != len(B){ return false } if len(A) <= 1 { return false } a := -1 b := -1 for i:= 0; i<len(A);...
2019-12-09 23:38:08 64
原创 No.145 - LeetCode1284 - 状压BFS - 黑白棋
class Solution {public: int getStatus(int loc,int status,int N,int M){ status ^= (1<<loc); // 非矩阵右边届 if(loc % M != 0) status ^= (1<<(loc-1)); // 非矩阵左边界...
2019-12-08 12:12:16 395
原创 No.144 - LeetCode1283 - 单调函数二分key
有个特殊情况,除数为0时,值为无穷大,所以0不能作为二分左端点。将1作为二分左端点又缺失case所以,ans为1时,单独处理小记,二分返回左端点和右端点是两种思路class Solution {public: long long doSum(int key,vector<int>& nums){ long long sum = 0; ...
2019-12-08 12:10:31 119
原创 No.143 - LeetCode1282
class Solution {public: vector<vector<int>> groupThePeople(vector<int>& groupSizes) { map<int,vector<int>> mp; int N = groupSizes.size(); ...
2019-12-08 12:04:25 146
原创 No.142 - LeetCode1281
class Solution {public: int subtractProductAndSum(int n) { int pro = 1; int sum = 0; while(n>0){ int a = n%10; n/=10; pro*=a; ...
2019-12-08 12:03:33 99
原创 No.141 - LeetCode492
class Solution {public: vector<int> constructRectangle(int area) { int A = (int)sqrt(area); for(int i=A;i>=1;i--){ int B = area/i; if(i*B == area)...
2019-12-06 00:40:33 75
原创 No.140 - LeetCode567
class Solution {public: bool judge(vector<int>& A,vector<int>& B){ for(int i=0;i<26;i++) if(A[i] != B[i]) return false; return true; } bool checkInc...
2019-12-06 00:11:12 68
原创 No.139 - LeetCode39 - 多重背包的可行性集合 - 去重
思路:dfs+回溯class Solution {public: void dfs(vector<int>& candidates,int target,int sum,vector<vector<int>>& ans,vector<int>& path,vector<int>& id){ ...
2019-12-04 00:00:24 450
原创 No.138 - LeetCode886 - 不存在奇数环的图
思路,枚举点BFS+层级染色:class Solution {public: bool possibleBipartition(int N, vector<vector<int>>& dislikes) { vector<int> color(N+1); vector<vector<int>&...
2019-12-03 23:38:49 78
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人