当前位置: 首页 > news >正文

网站建设报价方案网站后台地址破解

网站建设报价方案,网站后台地址破解,提供网站建设服务,网站设计提案LeetCode 39.组合总和 题目链接&#xff1a; LeetCode 39.组合总和 解题思路&#xff1a; 用回溯的方法&#xff0c;&#xff0c;注意这次回溯不是i1&#xff0c;而是i&#xff0c;是因为可用重复选取。 代码&#xff1a; class Solution { public:vector<vector<i…

LeetCode 39.组合总和

题目链接:

LeetCode 39.组合总和

解题思路:

用回溯的方法,,注意这次回溯不是i+1,而是i,是因为可用重复选取。

代码:

class Solution {
public:vector<vector<int>>result;vector<int>path;int sum=0;void traversal(vector<int>candidates,int target,int Index){if(sum==target){result.push_back(path);return;}else if(sum>target){return;}for(int i=Index;i<candidates.size();i++){path.push_back(candidates[i]);sum+=candidates[i];traversal(candidates,target,i);sum-=candidates[i];path.pop_back();}}vector<vector<int>> combinationSum(vector<int>& candidates, int target) {traversal(candidates,target,0);return result;}
};

LeetCode 40.组合总和2

题目链接:

LeetCode 40.组合总和2


解题思路:

用used数组看前面元素是否使用过,之后将数组排序,当和前面元素重复且前面元素没用过时,元素进行下一个,来去重。

代码:

class Solution {
public:vector<vector<int>>result;vector<int>path;void traversal(vector<int>& candidates, int target, int Index,int sum,vector<bool>used){if(sum==target){result.push_back(path);return;}for(int i=Index;i<candidates.size()&&sum+candidates[i]<=target;i++){if(i>0&&candidates[i]==candidates[i-1]&&used[i-1]==false){continue;}path.push_back(candidates[i]);sum+=candidates[i];used[i] =true;traversal(candidates,target,i+1,sum,used);sum-=candidates[i];path.pop_back();used[i]=false;}}vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {sort(candidates.begin(),candidates.end());path.clear();result.clear();vector<bool>used(candidates.size(),false);traversal(candidates,target,0,0,used);return result;}
};

LeetCode 131.分割回文串

题目链接:

LeetCode 131.分割回文串


解题思路:

将切割类比为组合问题,将元素索引变化为切割位置,逐个判断是不是回文的,之后进行回溯。

代码:

class Solution {
public:bool isPalindrome(const string& s, int start, int end) {for (int i = start, j = end; i < j; i++, j--) {if (s[i] != s[j]) {return false;}}return true;}vector<vector<string>> result;vector<string> path;void backtracking(string s, int Index) {if (Index >= s.size()) {result.push_back(path);return;}for (int i = Index; i < s.size(); i++) {if (isPalindrome(s, Index, i)) {path.push_back(s.substr(Index, i - Index + 1));} else {continue;}backtracking(s, i + 1);path.pop_back();}}vector<vector<string>> partition(string s) {backtracking(s, 0);return result;}
};

http://www.yayakq.cn/news/374769/

相关文章:

  • qq刷赞网站推广wordpress推荐管理
  • 建设企业查询网站装潢公司
  • 衡水做网站开发的网络营销与直播电商是做什么的
  • 路由器做映射后 内网可以访问到我的网站 但是外网无法访问石家庄本地招聘信息网
  • 阿里云可以放几个网站做网站赚钱好难
  • 怎么做正规网站seo搜索规则
  • 广州市增城区建设局网站模板建站什么意思
  • 高校招生网站建设公司网站主要功能
  • 青州网站黄页网站推广公司
  • 深圳网站建设公司jm3qwordpress的分类目录做成树
  • 精利手表网站电子商务烟台网站建设
  • 网站建设与管理用什么软件wordpress 微信主体
  • 网站开发建删除wordpress评论
  • 江苏国龙翔建设网站网页设计案例图片
  • 有什么做h5的网站内蒙古seo优化
  • 催收网站开发以家为主题做网站
  • 自己能建设网站吗建设门户网站的申请
  • 桐城市建设局网站我国好的室内设计公司排名
  • 建网站费用 优帮云网站电线电话图怎么做
  • 网站做代理需要空间是多少钱鹤壁做网站
  • 合肥建设网站首页软件开发网站开发
  • 网站诊断表网站建设公司基本流程
  • wapcms建站系统服务器 wordpress 邮件
  • 空壳网站清理东湖网站建设
  • 电脑网站在哪里找做网站学习什么
  • 哪里可以做网站开发中国十大网络科技公司排名
  • 用软件做模板下载网站网站 chat now怎么做
  • 建设银行的积分网站wordpress 504 gateway time-out
  • 动易学校网站管理系统 下载福田网站设计公司哪家好
  • 威县做网站哪里便宜网络设计与实施课程设计