【LeetCode算法练习(C语言)】Two Sum
来源:互联网 发布:php exec 返回值1 编辑:程序博客网 时间:2024/05/21 11:07
题目:
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].
链接:Two Sum
解法:穷举,时间O(n^2)
int* twoSum(int* nums, int numsSize, int target) { int *ret = (int *)malloc(2 * sizeof(int)); for (int i = 0; i < numsSize; i++) { for (int j = i + 1; j < numsSize; j++) { if (nums[i] + nums[j] == target) { ret[0] = i; ret[1] = j; return ret; } } } return ret;}
Runtime: 156 ms
阅读全文
0 0
- 【LeetCode算法练习(C语言)】Two Sum
- 【LeetCode算法练习(C语言)】Add Two Numbers
- LeetCode::Two Sum C语言
- LeetCode::Two Sum C语言
- Leetcode c语言-Two Sum
- 【LeetCode算法练习(C++)】3Sum
- 【LeetCode算法练习(C++)】4Sum
- 【LeetCode算法练习(C++)】Combination Sum
- 【LeetCode算法练习(C语言)】Median of Two Sorted Arrays
- 【LeetCode编程学习(C语言)】1.Two Sum
- leetcode 1. Two Sum (C语言)12
- leetcode 1:two sum(C语言)
- [C语言][LeetCode][1]Two Sum
- 1---LeetCode【Two Sum】|C语言|总结
- LeetCode-1-Two Sum(C语言实现)
- LeetCode 1. Two Sum(c语言实现)
- 【LeetCode算法练习(C++)】Merge Two Sorted Lists
- 【LeetCode算法练习(C++)】Divide Two Integers
- 剑指offer-3-Python实现二维数组的查找
- HDU
- 2017 Multi-University Training Contest No.4
- linux 通过哪个命令可以查看某个服务及其端口、进程号
- C-通用内存交换函数
- 【LeetCode算法练习(C语言)】Two Sum
- POJ 3233 Matrix Power Series(矩阵快速幂+二分求解)
- Ubuntu14.04云服务器使用wordpress搭建个人博客的个人总结
- fpga图像处理
- a 标签中如何设置其宽度和高度
- 电信面试题
- 【hdu4576】【期望Dp】Robot
- 使用setInterval 定时器
- 福州大学第十四届程序设计竞赛--平行四边形数