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. ctf中常见注入题源码及脚本分析

    1.代码审计发现 这里没有用escape_string,因此存在注入. function show($username){ global $conn; $sql = "select role ...

  2. Cinnamon桌面是怎么回事儿

    (linux mint 18.2 用户截图) Cinnamon的由来 在GNOME 3之前,GNOME是根据传统的桌面比拟(Desktop metaphor)而设计,到了GNOME 3便被GNOME ...

  3. Struts2总结优化登录与转发_02

    优化登录: 使用Struts2中的标签时,会生成大量的tr.td等,决定不使用Struts2中的标签,改用EL表达式,表单有大量数据时,不适合在控制层编写,所以用实体类封装URL中的参数. 控制层代码 ...

  4. [技术] OIer的STL入门教程

    注: 本文主要摘取STL在OI中的常用技巧应用, 所以可能会重点说明容器部分和算法部分, 且不会讨论所有支持的函数/操作并主要讨论 C++11 前支持的特性. 如果需要详细完整的介绍请自行查阅标准文档 ...

  5. SMS Error code: +CMS

    Error  Description CMS ERROR: 1 Unassigned number CMS ERROR: 8 Operator determined barring CMS ERROR ...

  6. NYOJ--927--dfs--The partial sum problem

    /* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 N ...

  7. jQuery相关知识总结一

    1day-jquery 1. 1 jQuery 1概念 * JavaScript(ECMA/DOM/BOM)在实际开发中,使用比较麻烦,有浏览器兼容问题. * JavaScript类库(JS库) 的目 ...

  8. 分辨率验证工具 - 【Firesizer】的使用

    Firesizer是一款测试分辨率的插件. 下载方式:Firefox工具栏——〉工具——〉附加组件--〉搜索Firesizer并安装,浏览器会自动重启 使用方式:浏览器右下角直接切换分辨率即可,如下图 ...

  9. AI类人工智能产品经理的丛林法则

     AI是大家都很关注的领域,然而对于大部分想要入行的同学来讲,AI的算法技术门槛相对较高,让很多空有热血但是缺少数学背景的同学望而却步.不知道什么时候,可能是“人人都是产品经理”这个论调的影响,产品经 ...

  10. Failed to load JavaHL Library. These are the errors that were encountered:

    问题: Failed to load JavaHL Library.These are the errors that were encountered:no msvcp100 in java.lib ...