国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode 1. Two Sum

2019-11-08 02:02:58
字體:
來源:轉載
供稿:網友

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].

程序代碼

/** * Note: The returned array must be malloced, assume caller calls free(). */int* twoSum(int* nums, int numsSize, int target) { int i=0,j=0; int a=-1,b=-1; int* ans; ans = (int*)malloc(sizeof(int)*2); for(i=0;i<numsSize-1;i++) { for(j=i+1;j<numsSize;j++) { if((nums[i]+nums[j])==target) { a = i; b = j; break; } } if(a>=0&&b>=0) break; } *ans = a; *(ans+1) = b; return ans;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长岭县| 棋牌| 襄城县| 恭城| 望都县| 衡阳市| 宜兰县| 长葛市| 梁河县| 东丽区| 土默特左旗| 乐陵市| 富阳市| 吉林市| 天镇县| 大邑县| 辽阳县| 天等县| 隆尧县| 和顺县| 南召县| 金昌市| 克拉玛依市| 永福县| 天柱县| 德格县| 临夏县| 泾阳县| 资中县| 庆元县| 河曲县| 霞浦县| 崇文区| 诏安县| 双峰县| 博白县| 芒康县| 赞皇县| 陇西县| 武鸣县| 绥宁县|