刷题第一题:数组去重,关键点:不用考虑优化,第一遍先做出来,二刷再去优化。

博客要求对给定的排序数组,在原地删除重复出现的元素,使每个元素仅出现一次,并返回移除后数组的新长度。需在不使用额外数组空间、使用 O(1) 额外空间的条件下原地修改输入数组。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
参考:

//    思路:从第二个数开始依次与第一个数比较,不相等指针后挪,相等则进入处理
//    处理:从相等的那个数后面一个开始,把值往前赋,等于是覆盖那个相等的值,len--,特
//    殊情况:最后一个数与被比较的目标数相等则len--再break
    public static int removeDuplicates(int[] nums) {
        int len = nums.length;
        for (int i = 0; i < len; i++) {//控制被比较的数的下标
            for (int j = i + 1; j < len; ) {//比较数的指针
                if (nums[i] == nums[j]) {//相等情况,进入,又分两种
                    //如果j已经到达len-1了,先len--再break
                    //不能先len-- 否则j已经>len-1了,永远break不了了。
                    if (j == len - 1) {
                        len--;
                        break;
                    //如果j没有达到len-1就把后面的数依次前挪呗,挪完也要len--
                    } else {
                        for (int k = j; k < len - 1; k++) {
                            nums[k] = nums[k + 1];
                        }
                        len--;
                    }
                } else {//不相等情况,指针后挪继续判断
                    j++;
                }
            }
        }
        return len;
    }
Combining visual and inertial measurements has become popular in mobile robotics, since the two sensing modalities offer complementary characteristics that make them the ideal choice for accurate Visual-Inertial Odometry or Simultaneous Localization and Mapping (SLAM). While historically the problem has been addressed with filtering, advancements in visual estimation suggest that non-linear optimization offers superior accuracy, while still tractable in complexity thanks to the sparsity of the underlying problem. Taking inspiration from these findings, we formulate a rigorously probabilistic cost function that combines reprojection errors of landmarks and inertial terms. The problem is kept tractable and thus ensuring real-time operation by limiting the optimization to a bounded window of keyframes through marginalization. Keyframes may be spaced in time by arbitrary intervals, while still related by linearized inertial terms. We present evaluation results on complementary datasets recorded with our custom-built stereo visual-inertial hardware that accurately synchronizes accelerometer and gyroscope measurements with imagery. A comparison of both a stereo and monocular version of our algorithm with and without online extrinsics estimation is shown with respect to ground truth. Furthermore, we compare the performance to an implementation of a state-of-the-art stochasic cloning sliding-window filter. This competititve reference implementation performs tightly-coupled filtering-based visual-inertial odometry. While our approach declaredly demands more computation, we show its superior performance in terms of accuracy.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值