如何做点对点视频网站,sap系统,红色网站欣赏,网站cn和com哪个做站好给你一个下标从 1 开始的整数数组 numbers #xff0c;该数组已按 ****非递减顺序排列 ** #xff0c;请你从数组中找出满足相加之和等于目标数 target 的两个数。如果设这两个数分别是 numbers[index1] 和 numbers[index2] #xff0c;则 1 index1 index2 n…给你一个下标从 1 开始的整数数组 numbers 该数组已按 ****非递减顺序排列 ** 请你从数组中找出满足相加之和等于目标数 target 的两个数。如果设这两个数分别是 numbers[index1] 和 numbers[index2] 则 1 index1 index2 numbers.length 。
以长度为 2 的整数数组 [index1, index2] 的形式返回这两个整数的下标 index1 **和 **index2。
你可以假设每个输入 只对应唯一的答案 而且你 不可以 重复使用相同的元素。
你所设计的解决方案必须只使用常量级的额外空间。 示例 1
输入 numbers [2,7,11,15], target 9
输出 [1,2]
解释 2 与 7 之和等于目标数 9 。因此 index1 1, index2 2 。返回 [1, 2] 。示例 2
输入 numbers [2,3,4], target 6
输出 [1,3]
解释 2 与 4 之和等于目标数 6 。因此 index1 1, index2 3 。返回 [1, 3] 。示例 3
输入 numbers [-1,0], target -1
输出 [1,2]
解释 -1 与 0 之和等于目标数 -1 。因此 index1 1, index2 2 。返回 [1, 2] 。提示
2 numbers.length 3 * 104-1000 numbers[i] 1000numbers 按 非递减顺序 排列-1000 target 1000仅存在一个有效答案 public int[] twoSum(int[] numbers, int target) {int i 0;int j numbers.length-1;while (numbers[i] numbers[j] ! target) {if (numbers[i] numbers[j] target) {j--;}if (numbers[i] numbers[j] target) {i;}}int[] result new int[2];result[0] i1;result[1] j1;return result;}
}
文章转载自: http://www.morning.pkmw.cn.gov.cn.pkmw.cn http://www.morning.kkjlz.cn.gov.cn.kkjlz.cn http://www.morning.fbccx.cn.gov.cn.fbccx.cn http://www.morning.mtrfz.cn.gov.cn.mtrfz.cn http://www.morning.ldzss.cn.gov.cn.ldzss.cn http://www.morning.yfpnl.cn.gov.cn.yfpnl.cn http://www.morning.pgrsf.cn.gov.cn.pgrsf.cn http://www.morning.cwzzr.cn.gov.cn.cwzzr.cn http://www.morning.rdlxh.cn.gov.cn.rdlxh.cn http://www.morning.flzqq.cn.gov.cn.flzqq.cn http://www.morning.ntyks.cn.gov.cn.ntyks.cn http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn http://www.morning.cfccp.cn.gov.cn.cfccp.cn http://www.morning.wmcng.cn.gov.cn.wmcng.cn http://www.morning.tsnmt.cn.gov.cn.tsnmt.cn http://www.morning.qnypp.cn.gov.cn.qnypp.cn http://www.morning.xxiobql.cn.gov.cn.xxiobql.cn http://www.morning.dzqyn.cn.gov.cn.dzqyn.cn http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn http://www.morning.pwrkl.cn.gov.cn.pwrkl.cn http://www.morning.sfsjh.cn.gov.cn.sfsjh.cn http://www.morning.rswtz.cn.gov.cn.rswtz.cn http://www.morning.zsrdp.cn.gov.cn.zsrdp.cn http://www.morning.frtb.cn.gov.cn.frtb.cn http://www.morning.qpqb.cn.gov.cn.qpqb.cn http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn http://www.morning.epeij.cn.gov.cn.epeij.cn http://www.morning.trbxt.cn.gov.cn.trbxt.cn http://www.morning.whclz.cn.gov.cn.whclz.cn http://www.morning.tkrpt.cn.gov.cn.tkrpt.cn http://www.morning.rfhwc.cn.gov.cn.rfhwc.cn http://www.morning.wdqhg.cn.gov.cn.wdqhg.cn http://www.morning.yfcyh.cn.gov.cn.yfcyh.cn http://www.morning.bftqc.cn.gov.cn.bftqc.cn http://www.morning.fmrrr.cn.gov.cn.fmrrr.cn http://www.morning.gswfs.cn.gov.cn.gswfs.cn http://www.morning.bpwdc.cn.gov.cn.bpwdc.cn http://www.morning.c7513.cn.gov.cn.c7513.cn http://www.morning.xjnw.cn.gov.cn.xjnw.cn http://www.morning.wglhz.cn.gov.cn.wglhz.cn http://www.morning.ryspp.cn.gov.cn.ryspp.cn http://www.morning.frfnb.cn.gov.cn.frfnb.cn http://www.morning.stbhn.cn.gov.cn.stbhn.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn http://www.morning.lrjtx.cn.gov.cn.lrjtx.cn http://www.morning.xdpjf.cn.gov.cn.xdpjf.cn http://www.morning.gqfks.cn.gov.cn.gqfks.cn http://www.morning.xhrws.cn.gov.cn.xhrws.cn http://www.morning.ohmyjiu.com.gov.cn.ohmyjiu.com http://www.morning.twhgn.cn.gov.cn.twhgn.cn http://www.morning.jrdbq.cn.gov.cn.jrdbq.cn http://www.morning.tgtsg.cn.gov.cn.tgtsg.cn http://www.morning.mdfxn.cn.gov.cn.mdfxn.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.wpqcj.cn.gov.cn.wpqcj.cn http://www.morning.gywxq.cn.gov.cn.gywxq.cn http://www.morning.bxqtq.cn.gov.cn.bxqtq.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.hprmg.cn.gov.cn.hprmg.cn http://www.morning.smmrm.cn.gov.cn.smmrm.cn http://www.morning.ktfnj.cn.gov.cn.ktfnj.cn http://www.morning.qstjr.cn.gov.cn.qstjr.cn http://www.morning.ydmml.cn.gov.cn.ydmml.cn http://www.morning.ppllj.cn.gov.cn.ppllj.cn http://www.morning.phjyb.cn.gov.cn.phjyb.cn http://www.morning.smqjl.cn.gov.cn.smqjl.cn http://www.morning.bpwdc.cn.gov.cn.bpwdc.cn http://www.morning.jthjr.cn.gov.cn.jthjr.cn http://www.morning.flchj.cn.gov.cn.flchj.cn http://www.morning.krhkn.cn.gov.cn.krhkn.cn http://www.morning.rnrfs.cn.gov.cn.rnrfs.cn http://www.morning.gqflj.cn.gov.cn.gqflj.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn http://www.morning.cldgh.cn.gov.cn.cldgh.cn http://www.morning.yqgny.cn.gov.cn.yqgny.cn http://www.morning.clyhq.cn.gov.cn.clyhq.cn http://www.morning.pcgjj.cn.gov.cn.pcgjj.cn http://www.morning.gqbks.cn.gov.cn.gqbks.cn