leetcode记录1
来源:互联网 发布:java字符串升序排列 编辑:程序博客网 时间:2024/06/05 19:44
这是一道soeasy的题目
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.
给一个数组和目标值,数组中的两个数相加是目标值,返回值是数组中的下标,题中给出一个例子
Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].
直接上代码就好啦,两循环就会解决:
public class Solution { public int[] twoSum(int[] nums, int target) { int [] a =new int[2]; for(int i = 0 ; i<nums.length;i++){ for(int j = i+1;j<nums.length; j++){ if(nums[i]+nums[j]==target){ a[0] = i;a[1] = j; break; } } } return a; }}
0 0
- leetcode记录1
- LeetCode解题记录(1)
- LeetCode记录
- leetcode 记录 191. Number of 1 Bits
- LeetCode习题记录(1)Two Sum
- Python leetcode记录(1) -Two Sum
- leetcode记录-Two Sum
- [LeetCode] Triangle 解题记录
- Leetcode记录7-单链表
- 记录LeetCode的一点一滴
- leetcode题目记录
- LeetCode bug记录
- leetcode记录-字符串系列
- leetcode记录 31-60
- leetcode 记录61-90
- leetcode 91-120记录
- leetcode-esay类型记录
- LeetCode解题记录
- cocos2d-js 加载本地图片 切割图片 并打乱
- php 通过ip获取地理位置
- 揭露强奸犯的黑客被判有罪?审视CFAA计算机欺诈法
- 在docker下创建自己的image
- JavaScript设计模式与开发实践 – 观察者模式
- leetcode记录1
- qt从root 用户切换到普通用户后,/home/linuxer/.config/QtProject/qtcreator/qtversion.xml : Permission
- C语言:单链表内节点的插入
- 基于Dragon Board410c与科大讯飞麦克风阵列模块的语音唤醒控制以及US-100超声波的实际应用
- 玩转树莓派-2_SSH连接
- iOS多线程的初步研究(一)-- NSThread
- setting的一些总结及settings.db字段含义
- 让C#可以像Javascript一样操作Json
- The Memory Sinkhole