1 题目

Given an array and a value, remove all instances of that value in place and return the new length.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

Hide Tags

Array Two Pointers

 
2 思路
好吧,感觉这个题目出的不是很好,按照题目要求,要改变A数组的长度,我一想,数组长度怎么改。。,看了答案,原来只是把和elem相同的元素,取另外一个元素覆盖这个相同的元素即可。也就是结果应该是前面startPosition(最终返回的结果)个元素里面没有elem,且是A[]数组里面排出elem剩下的元素。
 
3 代码
    public int removeElement(int[] A, int elem) {
int startPosition = 0;
for (int i = 0; i < A.length; i++) {
if (A[i] != elem) {
A[startPosition++] = A[i];
}
}
return startPosition;
}

[leetcode 50]remove element的更多相关文章

  1. Leetcode练习题Remove Element

    Leetcode练习题Remove Element Question: Given an array nums and a value val, remove all instances of tha ...

  2. leetCode 27.Remove Element (删除元素) 解题思路和方法

    Remove Element Given an array and a value, remove all instances of that value in place and return th ...

  3. LeetCode 027 Remove Element

    题目要求:Remove Element Given an array and a value, remove all instances of that value in place and retu ...

  4. LeetCode 27. Remove Element (移除元素)

    Given an array and a value, remove all instances of that value in place and return the new length. D ...

  5. [LeetCode] 27. Remove Element 移除元素

    Given an array nums and a value val, remove all instances of that value in-place and return the new ...

  6. LeetCode 27 Remove Element

    Problem: Given an array and a value, remove all instances of that value in place and return the new ...

  7. 【leetcode】Remove Element

    题目概述: Given an array and a value, remove all instances of that value in place and return the new len ...

  8. 【leetcode】Remove Element (easy)

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  9. Leetcode 27 Remove Element STL

    和remove zero类似的方法完成该题 class Solution { public: int removeElement(vector<int>& nums, int va ...

随机推荐

  1. 关于LCA的倍增解法的笔记

    emmmmm近日刚刚学习了LCA的倍增做法,写一篇BLOG来加强一下印象w 首先 何为LCA? LCA“光辉”是印度斯坦航空公司(HAL)为满足印度空军需要研制的单座单发轻型全天候超音速战斗攻击机,主 ...

  2. 厉害了,PS大神真的能改变世界!

    今天要介绍的这位PS大神 名叫 Katrina Yu 她的操作真的神了 不管多普通的场景 她都能帮你改头换面 在后院破旧的椅子上喝着咖啡 一转眼就骑着魔法扫帚 飞上了天,与月亮肩并肩 看原图还以为是在 ...

  3. Eclipse新建tld文件

    tld(tag lib description文件)就是以.tld结尾的XML文件 选好目录右键 --> New --> Other -->找到XML FIle --> Nex ...

  4. python正则表达式获取两段标记内的字符串

    比如获取绿色字符串 ModelData.PayTableData =[{"}, {"}, {"}]; ModelData.PayTableData1 =[{"} ...

  5. 【搜索】Shuffle'm Up

    运用第i个s12和第i+1个s12中,每个位置具有的确定的映射关系: pos = pos * 2 + 1 (pos < c) pos = pos * 2 - c * 2 (pos >= c ...

  6. Windows-universal-samples学习笔记系列五:Custom user interactions

    Custom user interactions Basic input Complex inking Inking Low latency input Simple inking Touch key ...

  7. Windows 平台 (UWP)应用设计

    Make Your Apps Cooperate with Cross-App Communication :  https://rewards.msdn.microsoft.com/Challeng ...

  8. 【Java】JABX实现对象与XML互转

    JABX简介 JAXB能够使用Jackson对JAXB注解的支持实现(jackson-module-jaxb-annotations),既方便生成XML,也方便生成JSON,这样一来可以更好的标志可以 ...

  9. KBMMW 4.84.00 发布

    kbmMW is a portable, highly scalable, high end application server and enterprise architecture integr ...

  10. Django的学习(三)————models

    models采用的的是类的方式,一个类对应一张表,在django中只需要对类的操作就可以完成数据表的操作,这种方式可以省去写sql语句,完成了sql语句的封装,被叫做 ORM(object relat ...