What if duplicates are allowed?

Would this affect the run-time complexity? How and why?

Write a function to determine if a given target is in the array.

 

 1 class Solution {
 2 public:
 3     bool search(vector<int>& nums, int target) {
 4         if(nums.size()==0) return false;
 5 
 6         for(int i=0;i<nums.size();i++)
 7         {
 8             if(target==nums[i])
 9                 return true;
10         }
11         return false;
12     }
13 };

 

posted on 2015-05-02 11:27  黄瓜小肥皂  阅读(95)  评论(0编辑  收藏  举报