leetcode1
public class Solution
{
public int[] TwoSum(int[] nums, int target)
{
var ary = new int[];
for (int i = ; i < nums.Length; i++)
{
for (int j = i + ; j < nums.Length; j++)
{
if (nums[i] + nums[j] == target)
{
ary[] = i;
ary[] = j;
return ary;
}
}
}
return ary;
}
}
https://leetcode.com/problems/two-sum/#/description
补充一个python的实现:
class Solution:
def twoSum(self, nums: 'List[int]', target: 'int') -> 'List[int]':
s = {}
for i in range(len(nums)):
n = nums[i]
cop = target - n
if cop in s.keys():
return [s[cop],i]
s[nums[i]] = i
return []
leetcode1的更多相关文章
- Leetcode1——两数之和 详细解析
Leetcode1--两数之和 题目分类:数组.哈希表的应用 1. 题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数 ...
- Count Complete Tree Nodes || LeetCode1
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * s ...
- LeetCode1:Two Sum
题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...
- leetcode1:在数组中找2个数的和正好等于一个给定值--哈希
package java_net_test; import java.util.HashMap; import java.util.Iterator; import java.util.Map; pu ...
- LeetCode1 Two Sum
题目 :Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- leetcode-1 Two Sum 找到数组中两数字和为指定和
问题描写叙述:在一个数组(无序)中高速找出两个数字,使得两个数字之和等于一个给定的值.如果数组中肯定存在至少一组满足要求. <剑指Offer>P214(有序数组) <编程之美& ...
- Leetcode-1.两数之和
题目描述: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数 ...
- [Swift]LeetCode1 .两数之和 | Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- leetcode1:两数之和
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 实例: 给定 nums = [2, 7, 11, 15],target = ...
随机推荐
- java运算符和流程图
- grep、head和tail
一.请给出打印test.txt内容时,不包含oldboy字符串的命令 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Globa ...
- UnsupportedClassVersionError: org/apache/maven/plugin/compiler/CompilerMojo : Unsupported major.minor version 51.0
这篇博主说明了原因并给出了相应的解决方案!!! 博文连接如下: https://www.cnblogs.com/qiumingcheng/p/7151629.html
- 4.App非功能测试总结
移动app测试的另一重要方面是移动app的非功能需求.移动app在推出市场或进行进一步开发前,移动测试员有许多需要测试的问题. 早期开发阶段要进行的第一个测试应该是实用性测试.通常是由alpha用户或 ...
- yarn依赖管理工具的使用
Yarn是Facebook发布的一款依赖管理工具,它比npm更快.更高效. 与NPM命令对照 npm install => yarn install npm install --save [pa ...
- JAVA基础部分复习(七、JAVA枚举类型使用)
/** * java中的枚举 * 枚举(enum),是指一个经过排序的.被打包成一个单一实体的项列表.一个枚举的实例可以使用枚举项列表中任意单一项的值. * 枚举在各个语言当中都有着广泛的应用,通常用 ...
- spring boot 项目无法访问静态页面
- JUnit4测试报错:class not found XXX
初学java框架,最近用eclipse跟着视频坐淘淘商城这个项目,其中使用了JUnit4做单元测试.当运行测试代码时,项目报错:class not found xxx. 借助了其他大神的博客,论坛等 ...
- Windows 下 安装 laravel(一些小笔记)
首先 安装完composer 下载地址 https://getcomposer.org/ 在 cmd 进入到 自己的项目访问目录 然后 输入命令:composer creat ...
- oracle query
不等值连接查询 员工工资级别 select e.empno,e.ename,e.sal,s.grade from emp e,salgrade s where e.sal between s.losa ...