leetcode
創(chuàng)新互聯(lián)公司是專業(yè)的迎江網(wǎng)站建設(shè)公司,迎江接單;提供成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行迎江網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
1.Two Sum
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.
Example:
Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].
UPDATE (2016/2/13):
The return format had been changed to zero-based indices. Please read the above updated description carefully.
#include#include int* twoS(int* nums,int numsize,int target) { int i=0; int j=numsize-1; int sum; int* res=(int*)malloc(2*sizeof(int)); if(nums==NULL) { return NULL; } while(i nums[i]+nums[j]) { i++; } else { j--; } } return NULL; } int main() { int a[]={2,3,7,11,15}; //printf("%d\n",sizeof(a)); int* p; p=twoS(a,4,9); if(p!=NULL) { printf("%d....%d",p[0],p[1]); }else { printf("NULLLLL"); } free(p); return 0; }