- 博客(52)
- 收藏
- 关注
原创 LeetCode1247
/就是已经去重后的obj,寻找到一个x,那么去寻找obj中的下一个x,这样只需变换一次,找不到x,就找y,需要变换两次。//去重,把相同索引且相同值的部分去掉,只需要留下不同的。//题目的重点在于把s1、s2先去重,然后以示意一和示意二中为基本情况,//因为最多剩余一个额外的x,所以最终的返回值是那样的形式。...
2022-08-10 00:05:26
171
原创 LeetCode33
class Solution {public: int search(vector& nums, int target) { int k=0; int obj; for(int i=0;inums[i+1]) { k=i+1; break; } }
2022-07-12 11:37:54
131
原创 LeetCode2315
class Solution {public: int countAsterisks(string s) { //尽量还是一趟遍历 bool flag=true; //用来记录是否处于竖线对中 int res=0; for(int i=0;i
2022-07-03 21:10:44
88
原创 LeetCode1143
class Solution {public: int longestCommonSubsequence(string text1, string text2) { int m=text1.size(); int n=text2.size(); vectordp(m+1,vector(n+1)); for(int i=0;i
2022-06-28 23:57:17
182
原创 LeetCode123
class Solution {public: int maxProfit(vector& prices) { int buy1=-100000; int sell1=0; int buy2=-100000; int sell2=0; for(int i=0;i
2022-06-28 15:44:00
190
原创 LeetCode2125
class Solution {public: int numberOfBeams(vector& bank) { int res=0; int up=0; int down=0; for(int i=0;i
2022-06-26 15:41:40
160
原创 LeetCode1013
class Solution {public: bool canThreePartsEqualSum(vector& arr) { int sum=0; for(auto i:arr) sum+=i; int yu=sum%3; int Thr=sum/3; if(yu!=0) return false; int sumTemp=0; bool fla
2022-06-26 12:51:33
61
原创 LeetCode526
class Solution {public: int res=0; vectortemp; int countArrangement(int n) { vectorused(n,false); backtracking(n,used); return res; } void backtracking(int n,vector&used) { if(temp.size
2022-06-11 22:05:11
47
原创 LeetCode2044
class Solution {public: int Max=0; int Num=0;//Num是最终答案 int countMaxOrSubsets(vector& nums) { backtracking(nums,0,0); return Num; } void backtracking(vector& nums,int st,int res) //这里的res表示数组或运算得到的值 { if(re...
2022-06-10 12:59:39
45
原创 LeetCode1415
class Solution {public: vectorres; string temp=""; string getHappyString(int n, int k) { string mp="abc"; backtracking(mp,n,k); if(k>res.size()) return ""; return res[k-1]; } void backtracking(s
2022-06-10 10:29:27
86
原创 LeetCode52
class Solution {public: int arr[10]; int res=0; int N; bool isSafe(int row,int col) { for (int k = 0; k < row; k++) //遍历放置了皇后的行 { if (arr[k] == col) return 0; //同一列 if (row - k == col - arr[k]) return 0; //从左
2022-06-10 10:15:46
187
原创 LeetCode93
class Solution {public: vectorres; string temp=""; vector restoreIpAddresses(string s) { backtracking(s,0,0); return res; } void backtracking(string s,int st,int Num) { if(temp.size()==s.size()+3&&Num=
2022-06-10 00:45:20
62
原创 LeetCode17
class Solution {public: vectormp; vectorres; string temp=""; vector letterCombinations(string digits) { if(digits=="") return mp; int len=digits.size(); mp.push_back("abc"); mp.push
2022-06-09 20:56:08
40
原创 LeetCode1079
class Solution {public: //copy别人的代码 int ans; int numTilePossibilities(string tiles) { int map[26]; ans=0; memset(map,0,sizeof(map)); for(int i=0;i
2022-06-07 21:29:44
87
原创 LeetCode131
class Solution {public: vectorres; vectortemp; vector partition(string s) { backtracking(s,0); return res; } void backtracking(string ori,int st) { if(st>=ori.size()) {
2022-06-07 12:24:26
74
原创 LeetCode797
class Solution {public: vectorres; vectortemp; vector allPathsSourceTarget(vector& graph) { temp.push_back(0); backtracking(0,0,graph); return res; } void backtracking(int curP
2022-06-07 07:48:14
68
原创 LeetCode90
class Solution {public: vectorres; vectortemp; vector subsetsWithDup(vector& nums) { sort(nums.begin(),nums.end()); backtracking(nums,0); return res; } void backtracking(vector&nu
2022-06-07 00:21:08
56
原创 LeetCode216
class Solution {public: vectorres; vectortemp; vector combinationSum3(int k, int n) { backtracking(n,k,1,0); return res; } void backtracking(int obj,int k,int st,int sum) { if(sum>obj)
2022-06-07 00:12:12
46
原创 LeetCode40
class Solution {public: vectorres; vectortemp; vector combinationSum2(vector& candidates, int target) { sort(candidates.begin(),candidates.end()); backtracking(target,candidates,0,0); return
2022-06-06 17:25:18
26
原创 LeetCode39
class Solution {public: vectorres; vectortemp; vector combinationSum(vector& candidates, int target) { backtracking(target,candidates,0,0); return res; } void backtracking(int obj,vector
2022-06-06 16:18:40
43
原创 LeetCode46
class Solution {public: vectorres; vectortemp; vector permute(vector& nums) { vectorused(nums.size(),false); backtracking(nums.size(),nums,used); return res; } void backtracking(
2022-06-05 23:38:17
48
原创 LeetCode2079
class Solution {public: int wateringPlants(vector& plants, int capacity) { int res=0; int obj=capacity; for(int i=0;i=plants[i]) { res++; }
2022-06-05 11:04:55
29
原创 LeetCode1475
class Solution {public: vector finalPrices(vector& prices) { //单调栈的做法,很妙 stackstk; for(int i=0;i
2022-06-05 10:46:29
83
原创 LeetCode1380
class Solution {public: vector luckyNumbers (vector& matrix) { vectorres; for(int i=0;i
2022-06-05 10:35:04
33
原创 LeetCode2620
class Solution {public: int maxAliveYear(vector& birth, vector& death) { // int len=birth.size(); // vectorvec(len,vector(2)); // for(int i=0;i
2022-06-05 09:37:27
41
原创 LeetCode58
class Solution {public: int lengthOfLastWord(string s) { int obj=s.size()-1; while(s[obj]==' ') obj--; for(int i=obj;i>=0;i--) { if(s[i]==' ') return obj-i; } return obj+1;
2022-06-04 22:13:33
48
原创 LeetCode856
class Solution {public: int scoreOfParentheses(string s) { stackstk; int res=0; for(int i=0;i
2022-06-03 20:23:28
48
原创 LeetCode1249
class Solution {public: string minRemoveToMakeValid(string s) { vectorleft;//表示左括号的索引 for(int i=0;i
2022-06-03 17:47:43
94
原创 LeetCode682
class Solution {public: int calPoints(vector& ops) { stackstk; for(auto str:ops) { if(str[0]>=48&&str[0]
2022-06-03 17:26:29
36
原创 LeetCode1052
class Solution {public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int res=0; for(int i=0;i
2022-06-03 09:59:34
58
原创 LeetCode2467/739
class Solution {public: vector dailyTemperatures(vector& temperatures) { vectorres(temperatures.size(),0); stackstk; for(int i=0;i
2022-06-03 00:33:54
34
原创 LeetCode1984
class Solution {public: int minimumDifference(vector& nums, int k) { if(nums.size()==1||k==1) return 0; sort(nums.begin(),nums.end()); int res=nums[nums.size()-1]; for(int i=0;i
2022-06-02 22:41:18
37
原创 LeetCode643
class Solution {public: double findMaxAverage(vector& nums, int k) { int temp=0; for(int j=0;j
2022-06-02 22:26:17
98
原创 LeetCode495
classSolution{public:intfindPoisonedDuration(vector<int>&timeSeries,intduration){intres=duration;intcur=timeSeries[0]+duration;//当前毒存在时间for(inti=1;i<timeSeries.size();i++){...
2022-05-31 18:06:02
36
原创 LeetCode258
classSolution{public:intAdd(intobj){inttemp=0;while(obj){temp+=obj%10;obj=(obj-obj%10)/10;}returntemp;}intaddDigits(intnum){while(num...
2022-05-31 17:42:43
73
原创 LeetCode219
classSolution{public:boolcontainsNearbyDuplicate(vector<int>&nums,intk){if(k==0)returnfalse;map<int,int>m;intlen=nums.size();for(inti=0;i<len;i++){...
2022-05-29 09:24:48
49
原创 LeetCode941
classSolution{public:boolvalidMountainArray(vector<int>&arr){if(arr.size()<3||arr[1]<=arr[0])returnfalse;intindex=1;for(inti=0;i<arr.size()-1;i++){if(arr...
2022-05-29 00:58:19
32
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人