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 ...
随机推荐
- ubuntu上安装nginx+mysql+php5-fpm(PHP5 - FastCGI Process Manager)
题外话:由于近段时间测试环境ssh链路质量不大好,经常短线.故我把整个安装过程放到screen里去执行,以防止断线中断了安装过程.执行screen -S install,这样断线后,只要再执行scre ...
- [BZOJ 4720][NOIP 2016] 换教室
记得某dalao立了"联赛要是考概率期望我直播吃键盘"的$flag$然后就有了这道题233333 4720: [Noip2016]换教室 Time Limit: 20 Sec M ...
- 小白浅论JAVA数组中“for加强版”
代码: /*String[] s=new String[]{"sdsfd","fgd","sdf"}; for(String a:s) Sy ...
- JavaScript获取客户端IP地址
1. 第三方接口 1) 这里提供一个搜狐接口的地址:http://pv.sohu.com/cityjson?ie=utf-8 ,将这个js引入到页面即可得到returnCitySN. 2) api.i ...
- NYOJ--284--广搜+优先队列--坦克大战
/* Name: NYOJ--284--坦克大战 Author: shen_渊 Date: 14/04/17 19:08 Description: 广度优先搜索+优先队列 注意清空地图 对输入地图进行 ...
- MySQL、Oracle数据库之操作系统版本选择
玩了快五年的Oracle,期间接触的操作系统大都是linux和aix,其中linux大部分为5.8的红帽子以及centos,oracle可以在上边运行稳定且需要安装其他与oracle相关的rpm包都是 ...
- 对接第三方平台JAVA接口问题推送和解决
前言 本节所讲为实际项目中与第三方对接出现的问题最后还是靠老大解决了问题以此作为备忘录,本篇分为三小节,一小节解析Java加密接口数据,二小节解析XML文件需注意问题,最后一节则是请求Java Soa ...
- CentOS 7 服务器配置--安装Java和Tomcat
一 安装 JAVA (jdk_8u121_linux_x64) #查看是否安装了OpenJDK #检查是否安装了JAVA java -version rpm -qa | grep java #卸载已安 ...
- ubuntu中安装搜狗输入法
1.查看系统中是否安装fcitx,libss2-1的依赖包,查看命令 dpkg -I | grep fcitx dpkg -I | grep libssh 没有安装的可以如下图命令安装 2.接下来我 ...
- TCP/IP协议和OSI协议
作为一个与网络密切相关的Web前端工程师,TCP/IP和OSI模型不可不知,至少要知道一下这些常识性知识,在这我做一下记录 TCP/IP协议簇: TCP/IP是一组协议的代名词,包括许多别的协议,组成 ...