My solution for twoSum problem ,its RE.Can anybody tell me why ?


  • 0

    class Solution {
    public:
    vector<int> twoSum(vector<int>& nums, int target) {
    int m=nums.size();
    int a[m];
    int i;
    int j;
    vector<int> b;
    for(i=0;i<=m-1;i++){
    a[i]=nums[i];
    }
    for(i=0;i<=(m-1);i++){
    if(a[i]<target){
    for(j=0;j<=(m-1);j++){
    if(a[i]+a[j]==target)
    {
    if(i<j){
    b[0]=i+1;
    b[1]=j+1;
    return b;
    }
    if(i>j){
    b[0]=j+1;
    b[1]=i+1;
    return b;
    }
    }
    }
    }
    }
    return b;
    }
    };


  • 0
    N

    这个是C语言吗,可是我只会java


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.