美文网首页
26.删除排序数组中的重复项-0301

26.删除排序数组中的重复项-0301

作者: 一条爱吃猫的小丑鱼 | 来源:发表于2019-03-01 19:58 被阅读0次
// 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