26.删除排序数组中的重复项-0301
// Remove Duplicates from Sorted Array
-(NSInteger)removeElementInSortedArray:(NSMutableArray <NSNumber *> *)array
{
if (array.count <= 1) {
return array.count;
}
int length = 1;
for (int i=1; i<array.count; i++) {
if (array[i-1].integerValue != array[i].integerValue) {
array[length ++] = array[i];
}
NSLog(@"%@",array);
}
if (array.count > length) {
[array removeObjectsInRange:NSMakeRange(length, array.count - length)];
}
NSLog(@"%@",array);
return length;
}
本文标题:26.删除排序数组中的重复项-0301
本文链接:https://www.haomeiwen.com/subject/sjujuqtx.html
网友评论