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 value, remove all instances of that value in place and return the new l...

【leetcode c++】27 Remove Element

Remove Element Given an array and a value, remove allinstances of that value in place and return th...
  • hqq39
  • hqq39
  • 2015年06月22日 00:48
  • 369

leetcode 27 Remove Element

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

LeetCode 27. Remove Element 题解 —— Java

题目链接:https://leetcode.com/problems/remove-element/#/description
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:27. Remove Element
举报原因:
原因补充:

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