leetcode 001 Two Sun
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的更多相关文章
- LeetCode #001# Two Sum(js描述)
索引 思路1:暴力搜索 思路2:聪明一点的搜索 思路3:利用HashMap巧解 问题描述:https://leetcode.com/problems/two-sum/ 思路1:暴力搜索 一个很自然的想 ...
- [leetCode][001] Maximum Product Subarray
题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...
- [Leetcode][001] Two Sum (Java)
题目在这里: https://leetcode.com/problems/two-sum/ [标签]Array; Hash Table [个人分析] 这个题目,我感觉也可以算是空间换时间的例子.如果是 ...
- Leetcode 001. 两数之和(扩展)
1.题目要求 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 2.解法一:暴力法(for*for,O(n*n)) ...
- leetcode 001
1 Two Sum Difficulty: Easy The Link: https://leetcode.com/problems/two-sum/description/ Description ...
- 【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 ...
- two Sum ---- LeetCode 001
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- Java for LeetCode 128 Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- LeetCode 算法题解 js 版 (001 Two Sum)
LeetCode 算法题解 js 版 (001 Two Sum) 两数之和 https://leetcode.com/problems/two-sum/submissions/ https://lee ...
随机推荐
- Android性能测试——Allocation Tracker(Device Monitor)
Android性能测试--Allocation Tracker(Device Monitor) Allocation Tracker 能做什么? 追踪内存分配信息,按顺序排列,这样我们就能清晰看出来某 ...
- vue2 和 webpack 配置环境使用
http://blog.csdn.net/fungleo/article/details/53171052
- Social Network Analysis的Centrality总结,以及networkx实现EigenCentrality,PageRank和KatzCentrality的对比
本文主要总结近期学习的Social Network Analysis(SNA)中的各种Centrality度量,我暂且翻译为中心度.本文主要是实战,理论方面几乎没有,因为对于庞大的SNA,我可能连门都 ...
- 使用Node.js实现简易MVC框架
在使用Node.js搭建静态资源服务器一文中我们完成了服务器对静态资源请求的处理,但并未涉及动态请求,目前还无法根据客户端发出的不同请求而返回个性化的内容.单靠静态资源岂能撑得起这些复杂的网站应用,本 ...
- Java 架构师之路(2)
一.技术 J2EE技术是架构师的基础.1.<Java编程思想> 初学Java时阅读这本书觉得好难,阅读第二遍时才觉得讲的很细致.这是一本不怕多读的好书. 2.<J2EE应用与BEA ...
- 再起航,我的学习笔记之JavaScript设计模式06(工厂方法模式)
上一次已经给大家介绍了简单工厂模式,相信大家对创建型设计模式有了初步的了解,本次我将给大家介绍的是工厂方法模式. 工厂方法模式 工厂方法模式(Factory Method):通过对产品类的抽象使其创建 ...
- 一次和matplotlib和numpy的初识及简单的异常值清理
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 ...
- 【NO.1】Jmeter-安装JDK- 配置Jmeter运行的环境 - 是使用Jmeter的前提
本篇文档是描述:当我们遇到没有安装JDK的Windows系统的电脑.Linux系统的电脑的时候,该怎么来安装JDK. 如果你不安装JDK,那么就没办法开始使用Jmeter. JDK下载地址 http: ...
- 关于isNAN()函数内进行的莫名其妙的隐式转换?!
isNaN(NaN); // true isNaN(undefined); // true isNaN({}); // true isNaN(true); // false isNaN(null); ...
- Linux 终端访问 FTP 及 上传下载 文件[转]
1. Linux 终端连接FTP [oracle@Dave ~]$ ftp 10.85.7.97 Connected to 10.85.7.97. 220 Serv-U FTP Server ...