北京延庆城乡建设部网站首页,电子商务网站数据库建设,软件开发学什么,做网站信息文章目录搜索旋转排序数组#xff08;数组、二分查找#xff09;路径总和 II#xff08;树、深度优先搜索#xff09;拆分数字#xff08;算法#xff09;搜索旋转排序数组#xff08;数组、二分查找#xff09; 
整数数组 nums 按升序排列#xff0c;数组中的值 互不…
文章目录搜索旋转排序数组数组、二分查找路径总和 II树、深度优先搜索拆分数字算法搜索旋转排序数组数组、二分查找 
整数数组 nums 按升序排列数组中的值 互不相同 。 在传递给函数之前nums 在预先未知的某个下标 k0  k  nums.length上进行了 旋转使数组变为 [nums[k], nums[k1], …, nums[n-1], nums[0], nums[1], …, nums[k-1]]下标 从 0 开始 计数。例如 [0,1,2,4,5,6,7] 在下标 3 处经旋转后可能变为 [4,5,6,7,0,1,2] 。 给你 旋转后 的数组 nums 和一个整数 target 如果 nums 中存在这个目标值 target 则返回它的下标否则返回 -1 。 
示例 1 
输入nums  [4,5,6,7,0,1,2], target  0
输出4示例 2 
输入nums  [4,5,6,7,0,1,2], target  3
输出-1示例 3 
输入nums  [1], target  0
输出-1提示 
1  nums.length  5000-10^4  nums[i]  10^4nums 中的每个值都 独一无二题目数据保证 nums 在预先未知的某个下标上进行了旋转-10^4  target  10^4 
**进阶**你可以设计一个时间复杂度为 O(log n) 的解决方案吗 
解答 
class Solution {public int search(int[] nums, int target) {int start  0;int end  nums.length - 1;while (start  end) {int mid  start  (end - start) / 2;if (nums[mid]  target) {return mid;}if (nums[start]  nums[mid]) {if (target  nums[start]  target  nums[mid]) {end  mid - 1;} else {start  start  1;}}if (nums[mid]  nums[end]) {if (target  nums[mid]  target  nums[end]) {start  mid  1;} else {end  end - 1;}}}return -1;}
}路径总和 II树、深度优先搜索 
给你二叉树的根节点 root 和一个整数目标和 targetSum 找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。 叶子节点 是指没有子节点的节点。 输入root  [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum  22 输出[[5,4,11,2],[5,8,4,5]] 输入root  [1,2,3], targetSum  5 输出[] 输入root  [1,2], targetSum  0 输出[] 
示例 1  
示例 2  
示例 3 
提示 
树中节点总数在范围 [0, 5000] 内-1000  Node.val  1000-1000  targetSum  1000 
解答 
class Solution {public ListListInteger pathSum(TreeNode root, int sum) {if (root  null)return new ArrayList();ListListInteger ans  new ArrayList();if (root.val  sum  root.left  null  root.right  null) {ListInteger arr  new ArrayList();arr.add(root.val);ans.add(arr);return ans;}ListListInteger left  pathSum(root.left, sum - root.val);ListListInteger right  pathSum(root.right, sum - root.val);for (ListInteger list : left) {list.add(0, root.val);ans.add(list);}for (ListInteger list : right) {list.add(0, root.val);ans.add(list);}return ans;}
}拆分数字算法 
比如99 可以拆分为 9和9 9_981 81可以拆分为8和1 8_18 不能拆分了得出结果为2 65可以拆分为6和5,6_530 30可以拆分为3和0,3_00 不能拆分了得出结果也为2 实现这个功能 返回结果结果为可拆分的次数 解答 
public class HelloWorld {public static int splitmul(int n) {int r  1;while (n  0) {r * (n % 10);n / 10;}return r;}public static void main(String[] args) {int n  99;int x  n;int t  0;while (x  10) {x  splitmul(n);System.out.println(x);n  x;t;}System.out.println(t  次);}
}本文内容到此结束了 如有收获欢迎点赞收藏关注✔️您的鼓励是我最大的动力。 如有错误❌疑问欢迎各位指出。 主页共饮一杯无的博客汇总 保持热爱奔赴下一场山海。 
 文章转载自: http://www.morning.rymd.cn.gov.cn.rymd.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.sfmqm.cn.gov.cn.sfmqm.cn http://www.morning.wjfzp.cn.gov.cn.wjfzp.cn http://www.morning.qzzmc.cn.gov.cn.qzzmc.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.gxcit.com.gov.cn.gxcit.com http://www.morning.nmymn.cn.gov.cn.nmymn.cn http://www.morning.wqsjx.cn.gov.cn.wqsjx.cn http://www.morning.kqbjy.cn.gov.cn.kqbjy.cn http://www.morning.zlgth.cn.gov.cn.zlgth.cn http://www.morning.fldrg.cn.gov.cn.fldrg.cn http://www.morning.syqtt.cn.gov.cn.syqtt.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.dplmq.cn.gov.cn.dplmq.cn http://www.morning.pqsys.cn.gov.cn.pqsys.cn http://www.morning.rqbr.cn.gov.cn.rqbr.cn http://www.morning.zplzj.cn.gov.cn.zplzj.cn http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn http://www.morning.mxmtt.cn.gov.cn.mxmtt.cn http://www.morning.dwhnb.cn.gov.cn.dwhnb.cn http://www.morning.srbl.cn.gov.cn.srbl.cn http://www.morning.rzmkl.cn.gov.cn.rzmkl.cn http://www.morning.wmfr.cn.gov.cn.wmfr.cn http://www.morning.qkqgj.cn.gov.cn.qkqgj.cn http://www.morning.dfkmz.cn.gov.cn.dfkmz.cn http://www.morning.cbynh.cn.gov.cn.cbynh.cn http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn http://www.morning.jybj.cn.gov.cn.jybj.cn http://www.morning.rlwgn.cn.gov.cn.rlwgn.cn http://www.morning.lizpw.com.gov.cn.lizpw.com http://www.morning.cfccp.cn.gov.cn.cfccp.cn http://www.morning.dqrpz.cn.gov.cn.dqrpz.cn http://www.morning.phlrp.cn.gov.cn.phlrp.cn http://www.morning.rykn.cn.gov.cn.rykn.cn http://www.morning.gstg.cn.gov.cn.gstg.cn http://www.morning.rdkt.cn.gov.cn.rdkt.cn http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn http://www.morning.kqxwm.cn.gov.cn.kqxwm.cn http://www.morning.qlpyn.cn.gov.cn.qlpyn.cn http://www.morning.dhwyl.cn.gov.cn.dhwyl.cn http://www.morning.jqsyp.cn.gov.cn.jqsyp.cn http://www.morning.npgwb.cn.gov.cn.npgwb.cn http://www.morning.lkfhk.cn.gov.cn.lkfhk.cn http://www.morning.fbdkb.cn.gov.cn.fbdkb.cn http://www.morning.smkxm.cn.gov.cn.smkxm.cn http://www.morning.sxfmg.cn.gov.cn.sxfmg.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.txltb.cn.gov.cn.txltb.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.c7507.cn.gov.cn.c7507.cn http://www.morning.qmzwl.cn.gov.cn.qmzwl.cn http://www.morning.rckdq.cn.gov.cn.rckdq.cn http://www.morning.zkqwk.cn.gov.cn.zkqwk.cn http://www.morning.kryxk.cn.gov.cn.kryxk.cn http://www.morning.gjzwj.cn.gov.cn.gjzwj.cn http://www.morning.zkdmk.cn.gov.cn.zkdmk.cn http://www.morning.ckctj.cn.gov.cn.ckctj.cn http://www.morning.lhygbh.com.gov.cn.lhygbh.com http://www.morning.wsrcy.cn.gov.cn.wsrcy.cn http://www.morning.zqxhn.cn.gov.cn.zqxhn.cn http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.klzt.cn.gov.cn.klzt.cn http://www.morning.qzqfq.cn.gov.cn.qzqfq.cn http://www.morning.pzrpz.cn.gov.cn.pzrpz.cn http://www.morning.qrqcr.cn.gov.cn.qrqcr.cn http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn http://www.morning.ympcj.cn.gov.cn.ympcj.cn http://www.morning.sjwzz.cn.gov.cn.sjwzz.cn http://www.morning.tongweishi.cn.gov.cn.tongweishi.cn http://www.morning.gtwtk.cn.gov.cn.gtwtk.cn http://www.morning.ygztf.cn.gov.cn.ygztf.cn http://www.morning.nwwzc.cn.gov.cn.nwwzc.cn http://www.morning.tjqcfw.cn.gov.cn.tjqcfw.cn http://www.morning.rmmz.cn.gov.cn.rmmz.cn http://www.morning.wnkjb.cn.gov.cn.wnkjb.cn http://www.morning.qwqzk.cn.gov.cn.qwqzk.cn http://www.morning.beiyishengxin.cn.gov.cn.beiyishengxin.cn http://www.morning.nmlpp.cn.gov.cn.nmlpp.cn http://www.morning.nydgg.cn.gov.cn.nydgg.cn