标签:
Question:
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Solution:
1 class Solution { 2 public: 3 int singleNumber(vector<int>& nums) { 4 sort(nums.begin(),nums.end()); 5 for(int i=0;i<nums.size();i+=2) 6 { 7 if(nums[i]!=nums[i+1]) 8 { 9 return nums[i]; 10 } 11 } 12 } 13 };
标签:
原文地址:http://www.cnblogs.com/riden/p/4631598.html