fork download
  1. class Solution {
  2. public:
  3. int singleNumber(vector<int>& nums) {
  4. sort(nums.begin(), nums.end());
  5.  
  6. if(nums[0] != nums[1])
  7. return nums[0];
  8. if(nums[nums.size() - 1] != nums[nums.size() - 2])
  9. return nums[nums.size() - 1];
  10.  
  11.  
  12. for(int i = 1; i < nums.size() - 1; i++) {
  13.  
  14. if(nums[i] != nums[i-1] && nums[i] != nums[i+1])
  15. return nums[i];
  16. }
  17. }
  18. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:22: error: 'vector' has not been declared
     int singleNumber(vector<int>& nums) {
                      ^
prog.cpp:3:28: error: expected ',' or '...' before '<' token
     int singleNumber(vector<int>& nums) {
                            ^
prog.cpp: In member function 'int Solution::singleNumber(int)':
prog.cpp:4:13: error: 'nums' was not declared in this scope
        sort(nums.begin(), nums.end());
             ^
prog.cpp:4:37: error: 'sort' was not declared in this scope
        sort(nums.begin(), nums.end());
                                     ^
stdout
Standard output is empty