当前位置: 首页 > 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.hkea.cn/news/419585/

相关文章:

  • 东莞做网站 南城石佳2023网站推广入口
  • 广东省省建设厅网站郴州网站建设网络推广平台
  • 校园网站推广方案怎么做应用商店优化
  • 巩义网站建设网络营销公司是做什么的
  • 做网站基本教程一站式营销平台
  • 杭州模板网站建设电脑培训网上培训班
  • 大连做网站不错的公司怎样把广告放到百度
  • 网站上面带官网字样怎么做的网站设计的流程
  • 有个网站是做视频相册的网球排名即时最新排名
  • 论坛网站备案流程图优化大师怎么提交作业
  • 织梦政府网站模板百度在线入口
  • 专业做婚纱摄影网站会员制营销
  • 网站内容丰富互动营销平台
  • 阿里巴巴logo高清图谷歌seo网站推广
  • 网站如何做内链seo高手是怎样炼成的
  • 设计师个人网站建设怎样注册一个自己的平台
  • 徐州营销网站建设产品线上推广渠道
  • 绍兴市网站建设公司企业官网搭建
  • 关于网页设计的网站免费发布信息网站大全
  • 郑州新闻头条seo基础教程
  • 做网站比较大的公司朔州seo
  • 如何制作私人网站福州专业的seo软件
  • 做网站主流技术南宁在哪里推广网站
  • 老板让我做网站负责人微博营销软件
  • 教我做网站百度打开
  • 网站开发时如何兼容电商运营是做什么的
  • 河北建设银行石家庄分行招聘网站怎么申请自己的网络平台
  • vs2008 做网站搜索引擎的工作原理是什么
  • 东莞常平做网站公司app营销策划方案
  • 爱用建站 小程序重庆网站制作公司