C++ solution O(n)...


  • -2
    W

    //本以为会超时,没想到……

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


  • 0

    暴力美學!
    Please provide more information - at least 30 characters


  • 0
    Z

    C 0ms
    int search(int* nums, int numsSize, int target) { for(int i=0; i<numsSize; i++){ if(nums[i] == target){ return i;
    } } return -1; }


Log in to reply
 

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