/ Published in: C
Given a sorted array return the new length of the array with no-repeated numbers.
Interesting test cases:
* All the same number
* No repetitions
* Empty array
* Negative size
* One element
Interesting test cases:
* All the same number
* No repetitions
* Empty array
* Negative size
* One element
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include<stdio.h> int deleteRepeatedNumbers(int list[], int size) { if(size < 1) return 0; int newLength = 1; for(int i = 1; i < size; i++) if(list[i-1] != list[i]) list[newLength++] = list[i]; return newLength; } int main() { int sortedArray[] = {1, 1, 1, 1, 2, 3, 4, 4, 5, 5, 6, 6 ,6 ,6, 11}; return 0; }