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 = ...
随机推荐
- 函数式语言(Functional language)简单介绍
函数式语言(functional language)一类程序设计语言,是一种非冯·诺伊曼式的程序设计语言.函数式语言主要成分是原始函数.定义函数和函数型. 函数式语言有:Haskell,Clean,M ...
- JavaScript的组成 | DOM/BOM
往期回顾 在上一期的<JavaScript的组成 | 核心-ECMAScript >☜里,我们有说到JavaScript 是由三大部分组成,分别是:核心ECMAScript.文档对象模型- ...
- HTML5:定位
定位 一.介绍: position设置块级元素相对于其父块的位置和相对于它自身应该在的位置,任何使用定位的元素都会成为块级元素. 1.属性值 属性值 描述 absolute 生成绝对定位的元素,相对于 ...
- Linux下不停止服务,清空nohup.out文件
转载:http://www.sucheasy.com/OracleFusionMiddleware/640.html 1.nohup.out的由来及作用 用途:LINUX命令用法,不挂断地运行命令. ...
- php批量检测和去掉bom头(转)
<?php //有些php文件由于不小心保存成了含bom头的格式而导致出现一系列的问题.以下是批量清除bom头的代码 if (isset ( $_GET ['dir'] )) { //confi ...
- 结构体的数据对齐 #pragma浅谈
之前若是有人拿个结构体或者联合体问我这个结构占用了多少字节的内存,我一定觉得这个人有点low, 直到某某公司的一个实习招聘模拟题的出现,让我不得不重新审视这个问题, 该问题大致如下: typedef ...
- css文本是否换行
关于文本换行有三个属性: white-space word-break word-wrap white-space normal 默认.空白会被浏览器忽略 pre 空白会被浏览器保留.其行为方式类似 ...
- yii2 Rbac实例 (做完以下这些 会有些小的报错,相信各位都能解决,大多数都是自己命名空间上的问题)。
首先我自己没有使用自带的user表 如果model层没有AuthItem.php 那就自建一个将下面这些内容写入 <?php namespace backend\models; use Yi ...
- restframework细节学习
一.后端发送列表.字典 1. 发送字典出现safe error,需要如下处理 def books(request): ll=[{},{}] # return HttpResponse(json.dum ...
- python:基本统计值计算(平均数,方差,中位数)
#CalStatisticsV1.py def getNum(): #获取用户不定长度的输入 nums=[] test=input("请输入要存储的数据(回车退出):") whil ...