C++ solution with 2 lines, 6ms


  • 0
    T
    int search(vector<int>& nums, int target) {
        if(find(nums.begin(),nums.end(),target)!= nums.end()) return distance(nums.begin(),find(nums.begin(),nums.end(),target));
        else return -1;
    }

Log in to reply
 

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