国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邓州市| 桃园县| 山阴县| 洪湖市| 鄱阳县| 台东县| 霍州市| 湛江市| 视频| 玛纳斯县| 赫章县| 中西区| 通江县| 阿尔山市| 德清县| 乌拉特前旗| 连平县| 仙居县| 玛曲县| 宣城市| 二手房| 双峰县| 娄烦县| 临湘市| 马龙县| 山阳县| 永清县| 武邑县| 浪卡子县| 民权县| 驻马店市| 乌鲁木齐市| 霍州市| 永城市| 克拉玛依市| 沾化县| 合川市| 合水县| 安泽县| 凯里市| 安庆市|