leetCode高频题刷题记录1;

以前没有怎么系统的学习过算法,数据结构等内容。越来越发心虚以后的工作去向,故在研一伊始,就准备朝着算法工程师的方向迈进。从数据结构到算法到机器学习到刷题,内容繁杂,仅作学习的记录;


leetCode 27题:RemoveElement:

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 by modifying the input array in-place with O(1) extra memory.

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

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


你可能感兴趣的:(刷题;求职;基础;)