32ms c++


  • 0
    B
    class Solution {
    public:
        bool search(vector<int>& nums, int target) {
            map<int,int> flag;
            map<int,int>::iterator it;
            int len=nums.size();
            for(int i=0;i<len;i++)
            {
                it=flag.find(nums[i]);
                if (it==flag.end())
                    flag[nums[i]]=i;
            }
            it=flag.find(target);
            if (it!=flag.end()) return true;
            else return false;
        }
    };
    

Log in to reply
 

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