标签:
Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
1 bool containsDuplicate(int* nums, int numsSize) 2 { 3 if(numsSize==0||numsSize==1) 4 return false; 5 6 bool flag=false; 7 for(int i=0;i<numsSize-1;i++) 8 { 9 flag=false; 10 for(int j=i+1;j<numsSize;j++) 11 { 12 if(nums[i]==nums[j]) 13 { 14 flag=true; 15 } 16 if(flag) 17 return true; 18 } 19 } 20 21 return false; 22 }
标签:
原文地址:http://www.cnblogs.com/vpoet/p/4660482.html