Leetcode -- 27, remove element

Paddy fields are elegant 2020-11-12 23:42:20
leetcode remove element

``````/**
* \* Created: liuhuichao
* \* Date: 2019/4/23
* \* Time: 7:32 PM
* \* Description: Remove elements
* Given an array nums And a value val, You need to remove all values in place equal to val The elements of , Returns the new length of the array after removal .
* <p>
* Don't use extra array space , You have to modify the input array in place and use O(1) Complete with extra space .
* <p>
* The order of elements can be changed . You don't need to think about the elements in the array that follow the new length .
* <p>
* Example 1:
* <p>
* Given nums = [3,2,2,3], val = 3,
* <p>
* Function should return the new length 2, also nums The first two elements in are 2.
* <p>
* You don't need to think about the elements in the array that follow the new length .
* Example 2:
* <p>
* Given nums = [0,1,2,2,3,0,4,2], val = 2,
* <p>
* Function should return the new length 5, also nums The first five elements in are 0, 1, 3, 0, 4.
* <p>
* Note that these five elements can be in any order .
* <p>
* You don't need to think about the elements in the array that follow the new length .
* explain :
* <p>
* Why is the return value an integer , But the output answer is array ?
* <p>
* Please note that , The input array is based on “ quote ” By way of transmission , This means that modifying the input array in a function is visible to the caller .
* <p>
* You can imagine the internal operation as follows :
* <p>
* // nums In order to “ quote ” By way of transmission . in other words , Do not make any copies of the arguments
* int len = removeElement(nums, val);
* <p>
* // Modifying the input array in a function is visible to the caller .
* // Based on the length returned by your function , It prints out all elements of the array in that length range .
``````