27. Remove Element

原创 2016年06月01日 18:37:21

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

Do not allocate extra space for another array, you must do this in place with constant memory.

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

Example:
Given input array nums = [3,2,2,3]val = 3

Your function should return length = 2, with the first two elements of nums being 2.

public class Solution {
    public int removeElement(int[] nums, int val) {
        
        int lengths = nums.length;
        
        int len = 0;
        
        for(int i=0;i<lengths;i++){
            
            if(nums[i]!=val){
                
                nums[len] = nums[i];
                
                len++;
                
            }
            
            
        }
        
        return len;
        
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

27. Remove Element \ 66. Plus One \ 88. Merge Sorted Array

27. Remove Element法一:class Solution { public: int removeElement(vector& nums, int val) { ...

Leetcode_27_Remove Element

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41577997 Remove Element Given ...

27. Remove Element

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

LeetCode_27---Remove Element

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

LeetCode笔记:27. Remove Element

固定内存下移除数组中特定的数字

Leetcode - Array - 27. Remove Element(第一道题)

1.Problem description Given an array and a value, remove all instances of that value in place and re...

LeetCode 27_Remove Element

这个题亦不是很难,并没有太多可说的,我们尽快结果了它吧。 题目也是要从数组中移除元素的,但算法还是有点儿小差别的,算是两个不同的小技巧吧。看题 Given an array and a v...

LertCode- 27. Remove Element

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

27. Remove Element [easy] (Python)

题目链接https://leetcode.com/problems/remove-element/题目原文 Given an array and a value, remove all insta...

LeetCode(27)Remove Element

题目如下 Given an array and a value, remove all instances of that value in place and return the new leng...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)