指定数组的下标,如果数组元素等于指定值
来源:互联网 发布:学seo好找工作吗 编辑:程序博客网 时间:2024/05/16 14:05
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution.
Example:
Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].
package com.dengpf.TwoNumbers;/** * Created by kobe73er on 16/12/17. */public class Solution { public int[] twoSum(int[] nums, int target) { int[] indexs = new int[2]; int i = 0; for (; i < nums.length; i++) { int j = i + 1; for (; j < nums.length;) { if ((nums[i] + nums[j]) == target) { indexs[0] = i; indexs[1] = j; return indexs; } j++; } } return indexs; } public static void main(String args[]) { int[] nums = {-3,4,3,90}; Solution solution = new Solution(); int[] result = solution.twoSum(nums, 0); for (int i = 0; i < result.length; i++) { System.out.println(result[i]); } }}
0 0
- 指定数组的下标,如果数组元素等于指定值
- 删除指定下标的数组
- 求数组中两个元素加起来等于指定的数
- js通过指定下标或指定元素进行删除数组
- 从长度指定的数组array中删除值等于v的元素
- js 删除数组指定的值,不是下标(转载)
- leetcode 删除数组指定值的元素
- java实现 数组中两个元素相加等于指定数的所有组合
- Two Sum(找出数组中两个和等于指定数字的元素)
- 从数组中找出两个元素的和等于指定数值,并输出位置。
- java 无序数组中两个元素相加等于指定的数 o(n)
- 不使用loop创建长度为100的数组,并且元素值等于下标
- 删除数组指定元素
- php按指定元素值去除数组元素的方法
- gcc 下指定下标的字符串数组初始化
- 阿里13年研发笔试题 - 寻找有序数组中元素值等于其下标的所有元素
- JS删除数组指定对象或者指定下标 删除数组重复值
- JS删除数组指定对象或者指定下标 删除数组重复值
- Core java第九版第四章对象与类
- Jsp电子商务之七 订单篇2
- Springmvc构造RESTful详细讲解
- 通过Javascript 对 CSS属性的设置 与 获取
- Apache+Tomcat配置集群组
- 指定数组的下标,如果数组元素等于指定值
- WinEdt && LaTex(五)—— 内容的排版
- test dword ptr [eax],eax ; probe page.
- java多态的简单理解
- ActiveMQ使用线程池实现消息的生产与消费
- 设置body背景图片跟随窗口大小变化
- 二叉树的相关操作
- Linux中使用SecureCRT上传、下载文件命令sz与rz用法实例
- mysql 闪回表工具