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

母婴用品商城网站建设手机app界面设计分析

母婴用品商城网站建设,手机app界面设计分析,开发者头条,建筑网片厂家货源平台一、电话号码的字母组合题目链接思路#xff1a;回溯三部曲。确定回溯函数参数#xff1a;题目中给的 digits#xff0c;还要有一个参数就是int型的index#xff08;记录遍历第几个数字#xff0c;就是用来遍历digits的#xff0c;同时也代表了递归的深度#xff09;回溯三部曲。确定回溯函数参数题目中给的 digits还要有一个参数就是int型的index记录遍历第几个数字就是用来遍历digits的同时也代表了递归的深度第三个参数numString(数字和字母映射)。确定终止条件如果index 等于 输入的数字个数digits.size了就return。确定单层遍历逻辑首先要取index指向的数字并找到对应的字符集然后for循环来处理这个字符集注意1解决三个问题数字和字母如何映射 使用map或者定义一个二维数组两个字母就两个for循环三个字符我就三个for循环以此类推然后发现代码根本写不出来输入1 * #按键等等异常情况2区别于普通的组合问题本题是多个集合求组合因为本题每一个数字代表的是不同集合也就是求不同集合之间的组合。3全局变量一个字符串sb来收集叶子节点的结果一个字符串数组result保存sb。解法class Solution {// 最终结果字符数组和单次符合条件结果ListString res new ArrayList();StringBuffer sb new StringBuffer();public ListString letterCombinations(String digits) {if (digits.length() 0 || digits null)return res;String[] numString {, , abc, def, ghi, jkl, mno, pqrs, tuv, wxyz};backTracking(digits, numString, 0);return res;}public void backTracking(String digits, String[] numString ,int num) {if (num digits.length()){res.add(sb.toString());return;}// digits.charAt(num)能够获取到当前的号码数字2-9String t numString[digits.charAt(num) - 0];for (int i 0; i t.length(); i) {sb.append(t.charAt(i));backTracking(digits, numString, num 1);sb.deleteCharAt(sb.length() - 1); //回溯}} }二、组合总和题目链接思路基本与组合总和III类似。区别有组合没有数量要求元素可无限重复选取注意如果是一个集合来求组合的话就需要startIndex否则会出现重复情况如果是多个集合取组合各个集合之间相互不影响那么就不用startIndex。解法未剪枝ListListInteger res new ArrayList(); LinkedListInteger path new LinkedList(); public ListListInteger combinationSum(int[] candidates, int target) {// sum, startIndex是开始位置也是candidates的索引back(candidates, target, 0,0);return res; }private void back(int[] candidates, int target, int sum, int startIndex) {if (sum target){res.add(new ArrayList(path));return;}if (sum target)return;for (int i startIndex; i candidates.length; i){path.add(candidates[i]);sum candidates[i];back(candidates, target, sum, i);sum - candidates[i];path.removeLast();} }剪枝优化1.对总集合排序之后如果下一层的sum就是本层的 sum candidates[i]已经大于target就可以结束本轮for循环的遍历。解法class Solution {ListListInteger res new ArrayList();LinkedListInteger path new LinkedList();public ListListInteger combinationSum(int[] candidates, int target) {Arrays.sort(candidates); // 先进行排序back(candidates, target, 0, 0);return res;}private void back(int[] candidates, int target, int sum, int startIndex) {if (sum target){res.add(new ArrayList(path));return;}if (sum target)return;// 多一步判断for (int i startIndex; i candidates.length sum candidates[i] target; i){path.add(candidates[i]);sum candidates[i];back(candidates, target, sum, i);sum - candidates[i];path.removeLast();}} }三、组合总和II题目链接思路与组合总和类似但区别于本题candidates 中的每个数字在每个组合中只能使用一次。本题数组candidates的元素是有重复的而39.组合总和 (opens new window)是无重复元素的数组candidates。也就是说组合里的元素可能有重复且只使用一次但组合之间不能重复。本题的难点在于区别2中集合数组candidates有重复元素但还不能有重复的组合。去重也去的是同一个树层上重复的值。代码里就是判断i startIndex candidates[i] candidates[i - 1]直接continue解法class Solution {ListListInteger res new ArrayList();LinkedListInteger path new LinkedList();public ListListInteger combinationSum2(int[] candidates, int target) {Arrays.sort(candidates); // 先进行排序back(candidates, target, 0, 0);return res;}private void back(int[] candidates, int target, int sum, int startIndex) {if (sum target){res.add(new ArrayList(path));return;}if (sum target)return;for (int i startIndex; i candidates.length sum candidates[i] target; i){// 碰到同一树层重复元素 直接continueif ( i startIndex candidates[i] candidates[i - 1] ) {continue;}path.add(candidates[i]);sum candidates[i];back(candidates, target, sum, i 1);sum - candidates[i];path.removeLast();}} }
http://www.hkea.cn/news/14503655/

相关文章:

  • 网站开发公司基本业务流程图广州微网站建设咨询
  • sns社交网站建设上海网络推广公司
  • 做网站可以申请专利吗开发官网
  • 热门课程自己做网站在国内做跨境电商怎么上外国网站
  • 设计有特色的网站windows优化大师是哪个公司的
  • 介绍网站ppt该怎么做高端企业网站建设制作
  • 行业网站设计公司wordpress+别名一致
  • 广东住房和城乡建设局网站首页Wordpress 淘宝客 页面
  • 免备案网站建站购物网站建设 费用
  • 医疗网站模板下载网站开发 网站建设
  • 哪个外贸网站开发客户比较好用Wordpress门徒同学
  • 网站开发对算法有要求么中天会展中心网站建设方案
  • 怎么做wp网站建e网室内设计网官网vr全景
  • 做经营网站怎么赚钱吗怎么自己电脑做网站服务器
  • 山东省住房和城乡建设部网站大连建站费用
  • 专做智能化施工的网站机械工业第六设计研究院有限公司
  • 松江做移动网站设计教育网站建设的素材
  • 网站单页在线制作2个wordpress
  • 自己做的网站提示不安全吗WordPress开启局域网
  • 本地建站教程更改wordpress主题名称
  • 做外单网站有哪些内容淘宝关键词搜索工具
  • 上海网站建设收费标准商标注册网上查询
  • 河南seo网站策划黄埔做网站的公
  • 网站建设ppt下载html编辑器的使用方法
  • 做视频卖给视频网站天元建设集团有限公司在哪个区
  • 无锡住房和城乡建设部网站成都旅游景点有哪些
  • 百度站长提交网址夹江网站建设
  • 做教育app的网站有哪些内容杭州网站界面设计
  • 成都市公园城市建设局网站广州五屏网站建设
  • 绿色能源网站模板毕节市建设厅网站