您的位置:首页 > 其它

leetCode高频题刷题记录1;

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

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  学习记录