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, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
 //时间O(N^2) 你的平方    空间 O(1)
int* twoSum_1(int* nums, int numsSize, int target) {
int i=;
int j=;
int *rtn=NULL;
for(i=;i<numsSize-;i++)
{
for(j=i+;j<numsSize;j++)
{
if(target-nums[j]==nums[i])
{
rtn=malloc(*sizeof(int));
rtn[]=i;
rtn[]=j;
return rtn; }
}
}
return rtn;
}

leetcode 001 Two Sun的更多相关文章

  1. LeetCode #001# Two Sum(js描述)

    索引 思路1:暴力搜索 思路2:聪明一点的搜索 思路3:利用HashMap巧解 问题描述:https://leetcode.com/problems/two-sum/ 思路1:暴力搜索 一个很自然的想 ...

  2. [leetCode][001] Maximum Product Subarray

    题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...

  3. [Leetcode][001] Two Sum (Java)

    题目在这里: https://leetcode.com/problems/two-sum/ [标签]Array; Hash Table [个人分析] 这个题目,我感觉也可以算是空间换时间的例子.如果是 ...

  4. Leetcode 001. 两数之和(扩展)

    1.题目要求 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 2.解法一:暴力法(for*for,O(n*n)) ...

  5. leetcode 001

    1 Two Sum Difficulty: Easy The Link: https://leetcode.com/problems/two-sum/description/ Description ...

  6. 【JAVA、C++】LeetCode 001 Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  7. two Sum ---- LeetCode 001

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  8. Java for LeetCode 128 Longest Consecutive Sequence

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. LeetCode 算法题解 js 版 (001 Two Sum)

    LeetCode 算法题解 js 版 (001 Two Sum) 两数之和 https://leetcode.com/problems/two-sum/submissions/ https://lee ...

随机推荐

  1. Asp.net MVC Razor常见问题及解决方法

    没有经验的童鞋就是这样磕磕碰碰出来的经验. 1,Datatype的错误提示消息无法自定义 这也许是Asp.net MVC的一个Bug.ViewModel中定义了DataType为Date字段: [Re ...

  2. ubuntu解压乱码

    乱码原因 问题一般出现在windows下压缩的在ubuntu中会出现这种情况. 其实就是windows和ubuntu下压缩的编码格式不同.windows下的编码格式为GBK,Ubuntu下的为UTF- ...

  3. 将域名转移到 Google Domains

    之前存放域名用过 Godaddy.Dynadot.Namesilo 也有阿里云(万网)和腾讯云(新网),这回就用 Google Domains 啦! 话说 Google Domains 早已是 201 ...

  4. Java生成MD5加密字符串代码实例

    这篇文章主要介绍了Java生成MD5加密字符串代码实例,本文对MD5的作用作了一些介绍,然后给出了Java下生成MD5加密字符串的代码示例,需要的朋友可以参考下   (1)一般使用的数据库中都会保存用 ...

  5. MAC上安装EndNote破解版的链接文件 以及某些安装好后有可能替换执照文件的方法

    一款非常好用的论文写作软件不多形容,开整: X7 mac版本(非免破解版本)链接: 点击我 X8 mac版本(大客户版本,免破解非常好用) 点击我 X8 windows版本(大客户版本,免破解非常好用 ...

  6. 防止DDoS攻击的方式

    针对企业的DDoS攻击持续增长,根据Akamai的调查报告,2015年DDoS攻击增长了史无前例的180% !面对 DDoS 攻击性挑战,我们应该建立有效的防御体系来抵御攻击.   1.网站IP减少公 ...

  7. 【 js 基础 】【 源码学习 】backbone 源码阅读(二)

    最近看完了 backbone.js 的源码,这里对于源码的细节就不再赘述了,大家可以 star 我的源码阅读项目(source-code-study)进行参考交流,有详细的源码注释,以及知识总结,同时 ...

  8. 双向循环链表(C语言描述)(四)

    下面以一个电子英汉词典程序(以下简称电子词典)为例,应用双向循环链表.分离数据结构,可以使逻辑代码独立于数据结构操作代码,程序结构更清晰,代码更简洁:电子词典的增.删.查.改操作分别对应于链表的插入. ...

  9. python8 字符串操作

    name = "my name is {name} and i am {year} old" print(name.capitalize()) print(name.count(& ...

  10. vue学习笔记(1)—— 组件化实现todoList

    一.环境搭建 1.npm 大型应用时推荐用npm安装,npm能很好的和webpack等模块打包器配合使用.具体安装步骤请参考网上的诸多教程.完成后使用如下命令安装vue. $ npm install ...