Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void swap(int *xp, int *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void bubbleSort(int arr[], int n)
- {
- int i, j;
- for (i = 0; i < n-1; i++)
- // Last i elements are already in place
- for (j = 0; j < n-i-1; j++)
- if (arr[j] > arr[j+1])
- swap(&arr[j], &arr[j+1]);
- }
- int singleNumber(int* nums, int numsSize){
- int i = 0, found = 0, o = 0, aux;
- bubbleSort(nums, numsSize);
- if (nums[0] != nums[1]) {
- found = nums[0];
- }
- if (nums[numsSize - 1] != nums[numsSize - 2]) {
- found = nums[numsSize - 2];
- }
- for (i = 1; i < numsSize - 2; i++) {
- if (nums[i] != nums[i - 1]) {
- if (nums[i] != nums[i + 1]) {
- found = nums[i];
- }
- }
- }
- return found;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement